Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Dec 16, 2024
1 parent 6ddc01d commit 3aba967
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES/526.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow the scheduler creation without runninmg event loop.
3 changes: 0 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ Scheduler
jobs could be iterated etc.: ``len(scheduler)``, ``for job in
scheduler``, ``job in scheduler`` operations are supported.

Class must be instantiated within a running event loop (e.g. in an
``async`` function).

* *close_timeout* is a timeout for job closing after cancellation,
``0.1`` by default. If job's closing time takes more than timeout a
message is logged by :meth:`Scheduler.call_exception_handler`.
Expand Down
8 changes: 6 additions & 2 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ async def coro() -> None:


async def test_spawn_non_bound_loop() -> None:
loop = asyncio.get_running_loop()

async def coro() -> None:
await asyncio.sleep(1)

Expand All @@ -47,8 +49,10 @@ async def coro() -> None:
job = await scheduler.spawn(coro())
assert not job.closed

assert scheduler._failed_task is not None
assert scheduler._failed_task.get_loop() is asyncio.get_running_loop()
ft = scheduler._failed_task
assert ft is not None
scheduler_loop = ft.get_loop() # type: ignore[unreachable]
assert scheduler_loop is loop

assert len(scheduler) == 1
assert list(scheduler) == [job]
Expand Down

0 comments on commit 3aba967

Please sign in to comment.