forked from goodboy/tractor
1
0
Fork 0

Add support for "debug mode"

When enabled a crashed actor will connect to the parent with `pdb`
in post mortem mode.
stin_char_relay
Tyler Goodlet 2020-07-23 13:32:29 -04:00
parent 23fee8820b
commit b1897da328
1 changed files with 13 additions and 0 deletions

View File

@ -18,6 +18,7 @@ from ._actor import Actor, _start_actor, Arbiter
from ._trionics import open_nursery from ._trionics import open_nursery
from ._state import current_actor from ._state import current_actor
from ._exceptions import RemoteActorError, ModuleNotExposed from ._exceptions import RemoteActorError, ModuleNotExposed
from ._debug import breakpoint, post_mortem
from . import msg from . import msg
from . import _spawn from . import _spawn
@ -103,14 +104,26 @@ def run(
# 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_run_in_process` (the new default).
start_method: Optional[str] = None, start_method: Optional[str] = None,
debug_mode: bool = False,
**kwargs, **kwargs,
) -> Any: ) -> Any:
"""Run a trio-actor async function in process. """Run a trio-actor async function in process.
This is tractor's main entry and the start point for any async actor. This is tractor's main entry and the start point for any async actor.
""" """
# mark top most level process as root actor
_state._runtime_vars['_is_root'] = True
if start_method is not None: if start_method is not None:
_spawn.try_set_start_method(start_method) _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')
return trio.run(_main, async_fn, args, kwargs, arbiter_addr, name) return trio.run(_main, async_fn, args, kwargs, arbiter_addr, name)