Add second implicit-runtime-boot branch
parent
b285db4c58
commit
983e66b31b
|
@ -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,20 +342,26 @@ async def open_nursery(
|
||||||
|
|
||||||
actor = current_actor(err_on_no_runtime=False)
|
actor = current_actor(err_on_no_runtime=False)
|
||||||
|
|
||||||
|
try:
|
||||||
if actor is None and is_main_process():
|
if actor is None and is_main_process():
|
||||||
|
|
||||||
# if we are the parent process start the actor runtime implicitly
|
# if we are the parent process start the actor runtime implicitly
|
||||||
log.info("Starting actor runtime!")
|
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
|
# mark us for teardown on exit
|
||||||
implicit_runtime = True
|
implicit_runtime = True
|
||||||
|
|
||||||
try:
|
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(
|
async with _open_and_supervise_one_cancels_all_nursery(
|
||||||
actor
|
actor
|
||||||
) as anursery:
|
) as anursery:
|
||||||
|
@ -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()
|
|
||||||
|
|
Loading…
Reference in New Issue