Rename parent-main inheritance flag.

Use `inherit_parent_main` across the actor APIs and helper to better describe the behavior, and restore the reviewer note at child bootstrap where the inherited `__main__` data is copied from `SpawnSpec`.
subint_spawner_backend
mahmoud 2026-04-06 06:30:00 +00:00 committed by mahmoudhas
parent 83b6c4270a
commit ea971d25aa
4 changed files with 19 additions and 14 deletions

View File

@ -204,23 +204,23 @@ def test_loglevel_propagated_to_subactor(
assert 'yoyoyo' in captured.err assert 'yoyoyo' in captured.err
def test_start_actor_can_skip_parent_main_replay( def test_start_actor_can_skip_parent_main_inheritance(
start_method, start_method,
reg_addr, reg_addr,
monkeypatch, monkeypatch,
): ):
if start_method != 'trio': if start_method != 'trio':
pytest.skip( pytest.skip(
'parent main replay opt-out only affects the trio spawn backend' 'parent main inheritance opt-out only affects the trio spawn backend'
) )
from tractor.spawn import _mp_fixup_main from tractor.spawn import _mp_fixup_main
monkeypatch.setattr( monkeypatch.setattr(
_mp_fixup_main, _mp_fixup_main,
'_mp_figure_out_main', '_mp_figure_out_main',
lambda replay_parent_main=True: ( lambda inherit_parent_main=True: (
{'init_main_from_name': __name__} {'init_main_from_name': __name__}
if replay_parent_main if inherit_parent_main
else {} else {}
), ),
) )
@ -238,7 +238,7 @@ def test_start_actor_can_skip_parent_main_replay(
isolated = await an.run_in_actor( isolated = await an.run_in_actor(
get_main_mod_name, get_main_mod_name,
name='isolated-parent-main', name='isolated-parent-main',
replay_parent_main=False, inherit_parent_main=False,
) )
assert await replaying.result() == '__mp_main__' assert await replaying.result() == '__mp_main__'

View File

@ -244,7 +244,7 @@ class Actor:
loglevel: str|None = None, loglevel: str|None = None,
registry_addrs: list[Address]|None = None, registry_addrs: list[Address]|None = None,
spawn_method: str|None = None, spawn_method: str|None = None,
replay_parent_main: bool = True, inherit_parent_main: bool = True,
arbiter_addr: UnwrappedAddress|None = None, arbiter_addr: UnwrappedAddress|None = None,
@ -269,7 +269,7 @@ class Actor:
# retrieve and store parent `__main__` data which # retrieve and store parent `__main__` data which
# will be passed to children # will be passed to children
self._parent_main_data = _mp_fixup_main._mp_figure_out_main( self._parent_main_data = _mp_fixup_main._mp_figure_out_main(
replay_parent_main, inherit_parent_main,
) )
# TODO? only add this when `is_debug_mode() == True` no? # TODO? only add this when `is_debug_mode() == True` no?
@ -1024,6 +1024,11 @@ class Actor:
) )
self._parent_main_data = spawnspec._parent_main_data self._parent_main_data = spawnspec._parent_main_data
# XXX QUESTION(s)^^^
# -[ ] already set in `.__init__()` right, but how is
# it diff from this blatant parent copy?
# -[ ] do we need/want the .__init__() value in
# just the root case orr?
return ( return (
chan, chan,

View File

@ -194,7 +194,7 @@ class ActorNursery:
loglevel: str|None = None, # set log level per subactor loglevel: str|None = None, # set log level per subactor
debug_mode: bool|None = None, debug_mode: bool|None = None,
infect_asyncio: bool = False, infect_asyncio: bool = False,
replay_parent_main: bool = True, inherit_parent_main: bool = True,
# TODO: ideally we can rm this once we no longer have # TODO: ideally we can rm this once we no longer have
# a `._ria_nursery` since the dependent APIs have been # a `._ria_nursery` since the dependent APIs have been
@ -207,7 +207,7 @@ class ActorNursery:
Start a (daemon) actor: an process that has no designated Start a (daemon) actor: an process that has no designated
"main task" besides the runtime. "main task" besides the runtime.
Pass ``replay_parent_main=False`` to keep this child on its own Pass ``inherit_parent_main=False`` to keep this child on its own
bootstrap module instead of re-running the parent's ``__main__`` bootstrap module instead of re-running the parent's ``__main__``
during startup. during startup.
@ -247,7 +247,7 @@ class ActorNursery:
# modules allowed to invoked funcs from # modules allowed to invoked funcs from
enable_modules=enable_modules, enable_modules=enable_modules,
loglevel=loglevel, loglevel=loglevel,
replay_parent_main=replay_parent_main, inherit_parent_main=inherit_parent_main,
# verbatim relay this actor's registrar addresses # verbatim relay this actor's registrar addresses
registry_addrs=current_actor().registry_addrs, registry_addrs=current_actor().registry_addrs,
@ -295,7 +295,7 @@ class ActorNursery:
enable_modules: list[str] | None = None, enable_modules: list[str] | None = None,
loglevel: str | None = None, # set log level per subactor loglevel: str | None = None, # set log level per subactor
infect_asyncio: bool = False, infect_asyncio: bool = False,
replay_parent_main: bool = True, inherit_parent_main: bool = True,
proc_kwargs: dict[str, any] = {}, proc_kwargs: dict[str, any] = {},
**kwargs, # explicit args to ``fn`` **kwargs, # explicit args to ``fn``
@ -327,7 +327,7 @@ class ActorNursery:
# use the run_in_actor nursery # use the run_in_actor nursery
nursery=self._ria_nursery, nursery=self._ria_nursery,
infect_asyncio=infect_asyncio, infect_asyncio=infect_asyncio,
replay_parent_main=replay_parent_main, inherit_parent_main=inherit_parent_main,
proc_kwargs=proc_kwargs proc_kwargs=proc_kwargs
) )

View File

@ -34,13 +34,13 @@ ORIGINAL_DIR = os.path.abspath(os.getcwd())
def _mp_figure_out_main( def _mp_figure_out_main(
replay_parent_main: bool = True, inherit_parent_main: bool = True,
) -> dict[str, str]: ) -> dict[str, str]:
"""Taken from ``multiprocessing.spawn.get_preparation_data()``. """Taken from ``multiprocessing.spawn.get_preparation_data()``.
Retrieve parent actor `__main__` module data. Retrieve parent actor `__main__` module data.
""" """
if not replay_parent_main: if not inherit_parent_main:
return {} return {}
d = {} d = {}