Skip to content

Commit 58c50be

Browse files
committed
3.12
1 parent 62bd8af commit 58c50be

File tree

7 files changed

+20
-22
lines changed

7 files changed

+20
-22
lines changed

async_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# limitations under the License.
1414

1515

16-
__version__ = "6.0.1"
16+
__version__ = "7.0.0"

async_utils/bg_loop.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
from collections.abc import Awaitable, Generator
2020
from concurrent.futures import Future
2121
from contextlib import contextmanager
22-
from typing import Any, TypeAlias, TypeVar
22+
from typing import Any, TypeVar
2323

2424
_T = TypeVar("_T")
2525

26-
_FutureLike: TypeAlias = asyncio.Future[_T] | Awaitable[_T]
26+
type _FutureLike[_T] = asyncio.Future[_T] | Awaitable[_T]
2727

2828
__all__ = ["threaded_loop"]
2929

@@ -52,12 +52,14 @@ def future_done_callback(_f: Future[Any]) -> object:
5252
return future.result()
5353

5454

55-
def run_forever(loop: asyncio.AbstractEventLoop) -> None:
55+
def run_forever(loop: asyncio.AbstractEventLoop, use_eager_task_factory: bool, /) -> None:
5656
asyncio.set_event_loop(loop)
57+
if use_eager_task_factory:
58+
loop.set_task_factory(asyncio.eager_task_factory)
5759
try:
5860
loop.run_forever()
5961
finally:
60-
loop.run_until_complete(asyncio.sleep(0.05))
62+
loop.run_until_complete(asyncio.sleep(0))
6163
tasks: set[asyncio.Task[Any]] = {t for t in asyncio.all_tasks(loop) if not t.done()}
6264
for t in tasks:
6365
t.cancel()
@@ -83,7 +85,7 @@ def run_forever(loop: asyncio.AbstractEventLoop) -> None:
8385

8486

8587
@contextmanager
86-
def threaded_loop() -> Generator[LoopWrapper, None, None]:
88+
def threaded_loop(*, use_eager_task_factory: bool = True) -> Generator[LoopWrapper, None, None]:
8789
"""Starts an event loop on a background thread,
8890
and yields an object with scheduling methods for interacting with
8991
the loop.
@@ -92,7 +94,7 @@ def threaded_loop() -> Generator[LoopWrapper, None, None]:
9294
loop = asyncio.new_event_loop()
9395
thread = None
9496
try:
95-
thread = threading.Thread(target=run_forever, args=(loop,))
97+
thread = threading.Thread(target=run_forever, args=(loop, use_eager_task_factory))
9698
thread.start()
9799
yield LoopWrapper(loop)
98100
finally:

async_utils/bg_tasks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
from __future__ import annotations
1616

1717
import asyncio
18-
from collections.abc import Coroutine, Generator
18+
from collections.abc import Coroutine
1919
from contextvars import Context
2020
from types import TracebackType
21-
from typing import Any, Self, TypeAlias, TypeVar
21+
from typing import Any, Self, TypeVar
2222

2323
_T = TypeVar("_T")
24-
_CoroutineLike: TypeAlias = Generator[Any, None, _T] | Coroutine[Any, Any, _T]
24+
type _CoroutineLike[_T] = Coroutine[Any, Any, _T]
2525

2626

2727
__all__ = ["BGTasks"]

async_utils/scheduler.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,19 @@
1818
from functools import total_ordering
1919
from time import time
2020
from types import TracebackType
21-
from typing import Any, Generic, TypeVar
21+
from typing import Any
2222

2323
__all__ = ("Scheduler",)
2424

2525
MISSING: Any = object()
26-
T = TypeVar("T")
2726

2827

2928
class CancelationToken:
3029
__slots__ = ()
3130

3231

3332
@total_ordering
34-
class _Task(Generic[T]):
33+
class _Task[T]:
3534
__slots__ = ("timestamp", "payload", "canceled", "cancel_token")
3635

3736
def __init__(self, timestamp: float, payload: T, /):
@@ -44,7 +43,7 @@ def __lt__(self, other: _Task[T]):
4443
return (self.timestamp, id(self)) < (other.timestamp, id(self))
4544

4645

47-
class Scheduler(Generic[T]):
46+
class Scheduler[T]:
4847
__tasks: dict[CancelationToken, _Task[T]]
4948
__tqueue: asyncio.PriorityQueue[_Task[T]]
5049
__closed: bool

async_utils/waterfall.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818
import asyncio
1919
import time
2020
from collections.abc import Callable, Coroutine, Sequence
21-
from typing import Any, Generic, Literal, TypeVar, overload
22-
23-
T = TypeVar("T")
21+
from typing import Any, Literal, overload
2422

2523
__all__ = ("Waterfall",)
2624

2725

28-
class Waterfall(Generic[T]):
26+
class Waterfall[T]:
2927
"""Class for batch event scheduling based on recurring intervals,
3028
with a quanity threshold which overrides the interval.
3129

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ exclude = [
1111
"docs",
1212
]
1313

14-
pythonVersion = "3.11"
14+
pythonVersion = "3.12"
1515
typeCheckingMode = "strict"
1616
pythonPlatform = "All"
1717
reportImportCycles = "error"
@@ -24,7 +24,7 @@ reportUnnecessaryTypeIgnoreComment = "warning"
2424
[tool.ruff]
2525

2626
line-length = 130
27-
target-version = "py311"
27+
target-version = "py312"
2828

2929
[tool.ruff.format]
3030
line-ending = "lf"

setup.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ classifiers =
1717
Natural Language :: English
1818
Typing :: Typed
1919
Programming Language :: Python :: 3 :: Only
20-
Programming Language :: Python :: 3.11
2120
Programming Language :: Python :: 3.12
2221
Programming Language :: Python :: 3.13
2322
license_files =
@@ -27,7 +26,7 @@ license_files =
2726

2827
[options]
2928
packages = find_namespace:
30-
python_requires = >=3.11.0
29+
python_requires = >=3.12.0
3130
include_package_data = True
3231

3332
[options.package_data]

0 commit comments

Comments
 (0)