Skip to content

Commit

Permalink
Fix asyncio.Queue creation on Python <3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Jan 24, 2025
1 parent 2fc0308 commit b12d3e5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/autoalloc/mock/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, handler: CommandHandler, key: str):
def run(
self, start_signal: queue.SimpleQueue, exception_queue: queue.SimpleQueue, key: str, handler: CommandHandler
):
stop_signal = asyncio.Queue()
stop_signal: Optional[asyncio.Queue] = None

async def handle_request(request):
command = request.match_info["cmd"]
Expand Down Expand Up @@ -149,6 +149,7 @@ async def handle_error(request, handler):
"""
Make sure that if any exception is thrown, we propagate it to the tests.
"""
nonlocal stop_signal
try:
return await handler(request)
except BaseException as e:
Expand All @@ -163,6 +164,13 @@ async def handle_error(request, handler):
)

async def body():
"""
On Python <3.10, asyncio.Queue cannot be created outside an event loop.
That is why it is created in such a complicated way here.
"""
nonlocal stop_signal
stop_signal = asyncio.Queue()

logging.info("Starting mock server")
runner = web.AppRunner(app)
await runner.setup()
Expand Down

0 comments on commit b12d3e5

Please sign in to comment.