forked from goodboy/tractor
Fixup _spawn.py comments to incorporate trip
parent
8264b7d136
commit
e671cb4f3b
|
@ -1,7 +1,5 @@
|
||||||
"""
|
"""
|
||||||
Process spawning.
|
Machinery for actor process spawning using multiple backends.
|
||||||
|
|
||||||
Mostly just wrapping around ``multiprocessing``.
|
|
||||||
"""
|
"""
|
||||||
import inspect
|
import inspect
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
|
@ -32,7 +30,7 @@ from ._actor import Actor, ActorFailure
|
||||||
|
|
||||||
log = get_logger('tractor')
|
log = get_logger('tractor')
|
||||||
|
|
||||||
# use trip as our default for now
|
# use trip as our default on *nix systems for now
|
||||||
if platform.system() != 'Windows':
|
if platform.system() != 'Windows':
|
||||||
_spawn_method: str = "trio_run_in_process"
|
_spawn_method: str = "trio_run_in_process"
|
||||||
else:
|
else:
|
||||||
|
@ -52,16 +50,19 @@ else:
|
||||||
|
|
||||||
|
|
||||||
def try_set_start_method(name: str) -> Optional[mp.context.BaseContext]:
|
def try_set_start_method(name: str) -> Optional[mp.context.BaseContext]:
|
||||||
"""Attempt to set the start method for ``multiprocess.Process`` spawning.
|
"""Attempt to set the start method for process starting, aka the "actor
|
||||||
|
spawning backend".
|
||||||
|
|
||||||
If the desired method is not supported the sub-interpreter (aka "spawn"
|
If the desired method is not supported this function will error. On Windows
|
||||||
method) is used.
|
the only supported option is the ``multiprocessing`` "spawn" method. The default
|
||||||
|
on *nix systems is ``trio_run_in_process``.
|
||||||
"""
|
"""
|
||||||
global _ctx
|
global _ctx
|
||||||
global _spawn_method
|
global _spawn_method
|
||||||
|
|
||||||
methods = mp.get_all_start_methods()
|
methods = mp.get_all_start_methods()
|
||||||
if 'fork' in methods:
|
if 'fork' in methods:
|
||||||
|
# forking is incompatible with ``trio``s global task tree
|
||||||
methods.remove('fork')
|
methods.remove('fork')
|
||||||
|
|
||||||
# no Windows support for trip yet
|
# no Windows support for trip yet
|
||||||
|
@ -266,10 +267,15 @@ async def new_proc(
|
||||||
# unblock parent task
|
# unblock parent task
|
||||||
task_status.started(portal)
|
task_status.started(portal)
|
||||||
|
|
||||||
# wait for ActorNursery.wait() to be called
|
# wait for ``ActorNursery`` block to signal that
|
||||||
# this is required to ensure synchronization
|
# subprocesses can be waited upon.
|
||||||
# with startup and registration of this actor in
|
# This is required to ensure synchronization
|
||||||
# ActorNursery.run_in_actor()
|
# with user code that may want to manually await results
|
||||||
|
# from nursery spawned sub-actors. We don't want the
|
||||||
|
# containing nurseries here to collect results or error
|
||||||
|
# while user code is still doing it's thing. Only after the
|
||||||
|
# nursery block closes do we allow subactor results to be
|
||||||
|
# awaited and reported upwards to the supervisor.
|
||||||
await actor_nursery._join_procs.wait()
|
await actor_nursery._join_procs.wait()
|
||||||
|
|
||||||
if portal in actor_nursery._cancel_after_result_on_exit:
|
if portal in actor_nursery._cancel_after_result_on_exit:
|
||||||
|
|
Loading…
Reference in New Issue