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+.
This commit is contained in:
Arun Babu Neelicattu 2022-03-03 19:11:57 +01:00 committed by GitHub
parent a836fb23bc
commit 9c1bf25304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -159,9 +159,19 @@ def main():
whitelist = set(sys.argv[1:])
if platform.system() == "Windows":
asyncio.set_event_loop(asyncio.ProactorEventLoop())
# for python version prior to 3.8, loop policy needs to be set explicitly
# https://docs.python.org/3/library/asyncio-policy.html#asyncio.DefaultEventLoopPolicy
try:
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
except AttributeError:
# python < 3.7 does not have asyncio.WindowsProactorEventLoopPolicy
asyncio.get_event_loop_policy().set_event_loop(asyncio.ProactorEventLoop())
asyncio.get_event_loop().run_until_complete(generate(whitelist, verbose))
try:
asyncio.run(generate(whitelist, verbose))
except AttributeError:
# compatibility code for python < 3.7
asyncio.get_event_loop().run_until_complete(generate(whitelist, verbose))
if __name__ == "__main__":