forked from goodboy/tractor
1
0
Fork 0

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
spawn_method_support
Tyler Goodlet 2019-03-06 12:44:16 -05:00
parent d6ca722bcc
commit dc5cc040e6
1 changed files with 12 additions and 3 deletions

View File

@ -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}")