forked from goodboy/tractor
1
0
Fork 0

Add second implicit-runtime-boot branch

mp_hang_search
Tyler Goodlet 2021-02-24 13:07:22 -05:00
parent b285db4c58
commit 983e66b31b
1 changed files with 23 additions and 19 deletions

View File

@ -5,7 +5,6 @@ from functools import partial
import multiprocessing as mp import multiprocessing as mp
from typing import Tuple, List, Dict, Optional from typing import Tuple, List, Dict, Optional
import typing import typing
from contextlib import AsyncExitStack
import warnings import warnings
import trio import trio
@ -343,25 +342,31 @@ async def open_nursery(
actor = current_actor(err_on_no_runtime=False) actor = current_actor(err_on_no_runtime=False)
if actor is None and is_main_process():
# if we are the parent process start the actor runtime implicitly
log.info("Starting actor runtime!")
root_runtime_stack = AsyncExitStack()
actor = await root_runtime_stack.enter_async_context(
open_root_actor(**kwargs)
)
assert actor is current_actor()
# mark us for teardown on exit
implicit_runtime = True
try: try:
async with _open_and_supervise_one_cancels_all_nursery( if actor is None and is_main_process():
actor
) as anursery:
yield anursery # if we are the parent process start the actor runtime implicitly
log.info("Starting actor runtime!")
# mark us for teardown on exit
implicit_runtime = True
async with open_root_actor(**kwargs) as actor:
assert actor is current_actor()
async with _open_and_supervise_one_cancels_all_nursery(
actor
) as anursery:
yield anursery
else: # sub-nursery case
async with _open_and_supervise_one_cancels_all_nursery(
actor
) as anursery:
yield anursery
finally: finally:
log.debug("Nursery teardown complete") log.debug("Nursery teardown complete")
@ -369,4 +374,3 @@ async def open_nursery(
# shutdown runtime if it was started # shutdown runtime if it was started
if implicit_runtime: if implicit_runtime:
log.info("Shutting down actor tree") log.info("Shutting down actor tree")
await root_runtime_stack.aclose()