Use event loop workaround only on windows

This avoids an unnecessary one-second sleep on other platforms. However, a
better "fix" for this sleep would be a less ugly workaround on windows.
This commit is contained in:
Joscha 2021-05-31 11:41:20 +02:00
parent b78eb64f3d
commit 84f775013f

View File

@ -1,6 +1,7 @@
import argparse import argparse
import asyncio import asyncio
import configparser import configparser
import os
import sys import sys
from pathlib import Path from pathlib import Path
@ -118,10 +119,18 @@ def main() -> None:
sys.exit(1) sys.exit(1)
try: try:
loop = asyncio.get_event_loop() if os.name == "nt":
loop.run_until_complete(pferd.run(args.debug_transforms)) # A "workaround" for the windows event loop somehow crashing after
loop.run_until_complete(asyncio.sleep(1)) # asyncio.run() completes. See:
loop.close() # https://bugs.python.org/issue39232
# https://github.com/encode/httpx/issues/914#issuecomment-780023632
# TODO Fix this properly
loop = asyncio.get_event_loop()
loop.run_until_complete(pferd.run(args.debug_transforms))
loop.run_until_complete(asyncio.sleep(1))
loop.close()
else:
asyncio.run(pferd.run(args.debug_transforms))
except ConfigOptionError as e: except ConfigOptionError as e:
log.unlock() log.unlock()
log.error(str(e)) log.error(str(e))