Explicitly handle `debug_mode` flag correctly

debug_tests
Tyler Goodlet 2020-09-12 11:48:57 -04:00
parent 8b6e9f5530
commit 09daba4c9c
1 changed files with 28 additions and 11 deletions

View File

@ -47,14 +47,25 @@ _default_arbiter_port = 1616
async def _main( async def _main(
async_fn: typing.Callable[..., typing.Awaitable], async_fn: typing.Callable[..., typing.Awaitable],
args: Tuple, args: Tuple,
kwargs: typing.Dict[str, typing.Any],
arbiter_addr: Tuple[str, int], arbiter_addr: Tuple[str, int],
name: Optional[str] = None, name: Optional[str] = None,
start_method: Optional[str] = None,
debug_mode: bool = False,
**kwargs: typing.Dict[str, typing.Any],
) -> typing.Any: ) -> typing.Any:
"""Async entry point for ``tractor``. """Async entry point for ``tractor``.
""" """
logger = log.get_logger('tractor') logger = log.get_logger('tractor')
if start_method is not None:
_spawn.try_set_start_method(start_method)
if debug_mode:
_state._runtime_vars['_debug_mode'] = True
# expose internal debug module to every actor allowing
# for use of ``await tractor.breakpoint()``
kwargs.setdefault('rpc_module_paths', []).append('tractor._debug')
main = partial(async_fn, *args) main = partial(async_fn, *args)
arbiter_addr = (host, port) = arbiter_addr or ( arbiter_addr = (host, port) = arbiter_addr or (
@ -109,7 +120,7 @@ def run(
), ),
# either the `multiprocessing` start method: # either the `multiprocessing` start method:
# https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods # https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods
# OR `trio_run_in_process` (the new default). # OR `trio` (the new default).
start_method: Optional[str] = None, start_method: Optional[str] = None,
debug_mode: bool = False, debug_mode: bool = False,
**kwargs, **kwargs,
@ -121,17 +132,23 @@ def run(
# mark top most level process as root actor # mark top most level process as root actor
_state._runtime_vars['_is_root'] = True _state._runtime_vars['_is_root'] = True
if start_method is not None: return trio.run(
_spawn.try_set_start_method(start_method) partial(
# our entry
_main,
if debug_mode: # user entry point
_state._runtime_vars['_debug_mode'] = True async_fn,
args,
# expose internal debug module to every actor allowing # global kwargs
# for use of ``await tractor.breakpoint()`` arbiter_addr=arbiter_addr,
kwargs.setdefault('rpc_module_paths', []).append('tractor._debug') name=name,
start_method=start_method,
return trio.run(_main, async_fn, args, kwargs, arbiter_addr, name) debug_mode=debug_mode,
**kwargs,
)
)
def run_daemon( def run_daemon(