Skip to content

Commit

Permalink
Explicitly handle debug_mode flag correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Sep 12, 2020
1 parent bc52e4a commit 482b623
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions tractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,25 @@
async def _main(
async_fn: typing.Callable[..., typing.Awaitable],
args: Tuple,
kwargs: typing.Dict[str, typing.Any],
arbiter_addr: Tuple[str, int],
name: Optional[str] = None,
start_method: Optional[str] = None,
debug_mode: bool = False,
**kwargs: typing.Dict[str, typing.Any],
) -> typing.Any:
"""Async entry point for ``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)

arbiter_addr = (host, port) = arbiter_addr or (
Expand Down Expand Up @@ -109,7 +120,7 @@ def run(
),
# either the `multiprocessing` start method:
# 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,
debug_mode: bool = False,
**kwargs,
Expand All @@ -121,17 +132,23 @@ def run(
# mark top most level process as root actor
_state._runtime_vars['_is_root'] = True

if start_method is not None:
_spawn.try_set_start_method(start_method)

if debug_mode:
_state._runtime_vars['_debug_mode'] = True
return trio.run(
partial(
# our entry
_main,

# expose internal debug module to every actor allowing
# for use of ``await tractor.breakpoint()``
kwargs.setdefault('rpc_module_paths', []).append('tractor._debug')
# user entry point
async_fn,
args,

return trio.run(_main, async_fn, args, kwargs, arbiter_addr, name)
# global kwargs
arbiter_addr=arbiter_addr,
name=name,
start_method=start_method,
debug_mode=debug_mode,
**kwargs,
)
)


def run_daemon(
Expand Down

0 comments on commit 482b623

Please sign in to comment.