Skip to content

Commit 9c1bf25

Browse files
authored
tests.generate: stop using asyncio.get_event_loop (#349)
The use of `asyncio.get_event_loop()` has been deprecated in python 3.10+. We replace this usage with `asyncio.run()` for python 3.7+.
1 parent a836fb2 commit 9c1bf25

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tests/generate.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,19 @@ def main():
159159
whitelist = set(sys.argv[1:])
160160

161161
if platform.system() == "Windows":
162-
asyncio.set_event_loop(asyncio.ProactorEventLoop())
163-
164-
asyncio.get_event_loop().run_until_complete(generate(whitelist, verbose))
162+
# for python version prior to 3.8, loop policy needs to be set explicitly
163+
# https://docs.python.org/3/library/asyncio-policy.html#asyncio.DefaultEventLoopPolicy
164+
try:
165+
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
166+
except AttributeError:
167+
# python < 3.7 does not have asyncio.WindowsProactorEventLoopPolicy
168+
asyncio.get_event_loop_policy().set_event_loop(asyncio.ProactorEventLoop())
169+
170+
try:
171+
asyncio.run(generate(whitelist, verbose))
172+
except AttributeError:
173+
# compatibility code for python < 3.7
174+
asyncio.get_event_loop().run_until_complete(generate(whitelist, verbose))
165175

166176

167177
if __name__ == "__main__":

0 commit comments

Comments
 (0)