diff --git a/examples/blender/blender.py b/examples/blender/blender.py index e9b328ec6..88d035709 100755 --- a/examples/blender/blender.py +++ b/examples/blender/blender.py @@ -86,6 +86,9 @@ async def worker(ctx: WorkContext, tasks): parser.set_defaults(log_file="blender-yapapi.log") args = parser.parse_args() + # This is only required when running on Windows with Python prior to 3.8: + utils.windows_event_loop_fix() + enable_default_logger(log_file=args.log_file) loop = asyncio.get_event_loop() subnet = args.subnet_tag diff --git a/examples/utils.py b/examples/utils.py index f121fdccf..ce08aad26 100644 --- a/examples/utils.py +++ b/examples/utils.py @@ -1,5 +1,7 @@ """Utilities for yapapi example scripts.""" import argparse +import asyncio +import sys TEXT_COLOR_RED = "\033[31;1m" TEXT_COLOR_GREEN = "\033[32;1m" @@ -21,3 +23,15 @@ def build_parser(description: str): "--log-file", default=None, help="Log file for YAPAPI; default: %(default)s" ) return parser + + +def windows_event_loop_fix(): + """Set up asyncio to use ProactorEventLoop implementation for new event loops on Windows.""" + + # For Python 3.8 ProactorEventLoop is already the default on Windows + if sys.platform == "win32" and sys.version_info < (3, 8): + + class _WindowsEventPolicy(asyncio.events.BaseDefaultEventLoopPolicy): + _loop_factory = asyncio.windows_events.ProactorEventLoop + + asyncio.set_event_loop_policy(_WindowsEventPolicy()) diff --git a/examples/yacat/yacat.py b/examples/yacat/yacat.py index ae0399b5f..0bcd4315c 100644 --- a/examples/yacat/yacat.py +++ b/examples/yacat/yacat.py @@ -140,6 +140,9 @@ async def worker_find_password(ctx: WorkContext, tasks): args = parser.parse_args() + # This is only required when running on Windows with Python prior to 3.8: + utils.windows_event_loop_fix() + enable_default_logger(log_file=args.log_file) sys.stderr.write( diff --git a/pyproject.toml b/pyproject.toml index 27bbb15b8..71ec7a9e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api" [tool.poetry] name = "yapapi" -version = "0.3.0" +version = "0.3.1-alpha.0" description = "High-level Python API for the New Golem" authors = ["Przemysław K. Rekucki "] license = "LGPL-3.0-or-later"