Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
fix: Regression in Python 3.10 due to #10 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol authored Apr 19, 2023
1 parent b8297f4 commit d6f2ea2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aiomonitor/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def __init__(
persistent: bool = False,
**kwargs,
) -> None:
if sys.version_info < (3, 11):
kwargs.pop("context")
super().__init__(*args, **kwargs)
self._termination_info_queue = termination_info_queue
self._cancellation_chain_queue = cancellation_chain_queue
Expand Down
21 changes: 21 additions & 0 deletions tests/test_monitor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import contextvars
import sys
import telnetlib
import threading
import time
Expand Down Expand Up @@ -147,6 +148,26 @@ def test_basic_monitor(monitor, tn_client, loop):


def test_monitor_task_factory():
async def do():
await asyncio.sleep(0)
myself = asyncio.current_task()
assert myself is not None
assert myself.get_name() == "mytask"

async def main():
loop = asyncio.get_running_loop()
with Monitor(loop, console_enabled=False, hook_task_factory=True):
t = asyncio.create_task(do(), name="mytask")
await t

asyncio.run(main())


@pytest.mark.skipif(
sys.version_info < (3, 11),
reason="The context argument of asyncio.create_task() is added in Python 3.11",
)
def test_monitor_task_factory_with_context():
ctx = contextvars.Context()
# This context is bound at the outermost scope,
# and inside it the initial value of myvar is kept intact.
Expand Down

0 comments on commit d6f2ea2

Please sign in to comment.