Skip to content

Commit

Permalink
Merge pull request #106 from golemfactory/0.3-winpy3.6-fix
Browse files Browse the repository at this point in the history
add a work-around to make the examples work on win+py3.6/3.7
  • Loading branch information
azawlocki authored Oct 23, 2020
2 parents c6b9083 + 8e8809d commit 96f841b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/blender/blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions examples/utils.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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())
3 changes: 3 additions & 0 deletions examples/yacat/yacat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
license = "LGPL-3.0-or-later"
Expand Down

0 comments on commit 96f841b

Please sign in to comment.