From dc5cc040e6a2d4671e14f42a2f4648b7f631cfb3 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 6 Mar 2019 12:44:16 -0500 Subject: [PATCH] Try to support waiting on Windows processes This pokes around a little in `trio` hazmat but it *should work* as it piggy backs on the new cross platform subprocess support. Relates to #59 --- tractor/_trionics.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tractor/_trionics.py b/tractor/_trionics.py index 71f8d48..bf83179 100644 --- a/tractor/_trionics.py +++ b/tractor/_trionics.py @@ -1,15 +1,15 @@ """ ``trio`` inspired apis and helpers """ -import multiprocessing as mp import inspect +import platform +import multiprocessing as mp from typing import Tuple, List, Dict, Optional, Any import typing import trio from async_generator import asynccontextmanager, aclosing -# from . import _forkserver_hackzorz from ._state import current_actor from .log import get_logger, get_loglevel from ._actor import Actor, ActorFailure @@ -17,6 +17,14 @@ from ._portal import Portal from . import _spawn +if platform.system() == 'Windows': + async def proc_waiter(proc: mp.Process) -> None: + await trio.hazmat.WaitForSingleObject(proc.sentinel) +else: + async def proc_waiter(proc: mp.Process) -> None: + await trio.hazmat.wait_readable(proc.sentinel) + + log = get_logger('tractor') @@ -180,7 +188,8 @@ class ActorNursery: ) -> None: # TODO: timeout block here? if proc.is_alive(): - await trio.hazmat.wait_readable(proc.sentinel) + await proc_waiter(proc) + # please god don't hang proc.join() log.debug(f"Joined {proc}")