Skip to content

Commit 64dff42

Browse files
authored
[mypyc] Fix async mypyc tests on Windows (#19578)
This is part of fixing the failed tests in #19545 The async tests previously used many invocations of `asyncio.run`, which likely caused issues with event loop management. The documentation for `asyncio.run` states: > This function cannot be called when another asyncio event loop is running in the same thread. ... > This function should be used as a main entry point for asyncio programs, and should ideally only be called once. Calling `asyncio.run` multiple times could cause the test processes to hang for strange event loop reasons. This commit converts most test cases to be run in a single event loop managed by the default driver, which is now async aware. Not all tests could be converted, e.g. the test that runs an async function in a sync context. However, the test suite does succeed with these changes, and these tests can be further modified if needed.
1 parent 8f48f1b commit 64dff42

File tree

2 files changed

+185
-218
lines changed

2 files changed

+185
-218
lines changed

mypyc/test-data/driver/driver.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
import sys
1111
import native
12+
import asyncio
13+
import inspect
14+
15+
evloop = asyncio.new_event_loop()
1216

1317
failures = []
1418
tests_run = 0
@@ -18,7 +22,10 @@
1822
test_func = getattr(native, name)
1923
tests_run += 1
2024
try:
21-
test_func()
25+
if inspect.iscoroutinefunction(test_func):
26+
evloop.run_until_complete(test_func)
27+
else:
28+
test_func()
2229
except Exception as e:
2330
failures.append((name, sys.exc_info()))
2431

0 commit comments

Comments
 (0)