forked from goodboy/tractor
1
0
Fork 0

Merge pull request #194 from goodboy/sync_breakpoint

Support sync code breakpointing via built-in
first_pypi_release
goodboy 2021-02-21 17:49:43 -05:00 committed by GitHub
commit 35dc56d2c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 11 deletions

View File

@ -274,15 +274,32 @@ def _mk_pdb():
return pdb return pdb
def _set_trace(actor): def _set_trace(actor=None):
pdb = _mk_pdb()
if actor is not None:
log.runtime(f"\nAttaching pdb to actor: {actor.uid}\n") log.runtime(f"\nAttaching pdb to actor: {actor.uid}\n")
pdb = _mk_pdb()
pdb.set_trace( pdb.set_trace(
# start 2 levels up in user code # start 2 levels up in user code
frame=sys._getframe().f_back.f_back, frame=sys._getframe().f_back.f_back,
) )
else:
# we entered the global ``breakpoint()`` built-in from sync code
global _in_debug, _pdb_release_hook
_in_debug = 'sync'
def nuttin():
pass
_pdb_release_hook = nuttin
pdb.set_trace(
# start 2 levels up in user code
frame=sys._getframe().f_back,
)
breakpoint = partial( breakpoint = partial(
_breakpoint, _breakpoint,

View File

@ -64,8 +64,7 @@ def _trio_main(
# we don't need it thanks to our cancellation machinery. # we don't need it thanks to our cancellation machinery.
signal.signal(signal.SIGINT, signal.SIG_IGN) signal.signal(signal.SIGINT, signal.SIG_IGN)
# TODO: make a global func to set this or is it too hacky? log.info(f"Started new trio process for {actor.uid}")
# os.environ['PYTHONBREAKPOINT'] = 'tractor._debug.breakpoint'
if actor.loglevel is not None: if actor.loglevel is not None:
log.info( log.info(

View File

@ -67,7 +67,7 @@ def _fixup_main_from_name(mod_name: str) -> None:
main_module = types.ModuleType("__mp_main__") main_module = types.ModuleType("__mp_main__")
main_content = runpy.run_module(mod_name, main_content = runpy.run_module(mod_name,
run_name="__mp_main__", run_name="__mp_main__",
alter_sys=True) alter_sys=True) # type: ignore
main_module.__dict__.update(main_content) main_module.__dict__.update(main_content)
sys.modules['__main__'] = sys.modules['__mp_main__'] = main_module sys.modules['__main__'] = sys.modules['__mp_main__'] = main_module
@ -95,6 +95,6 @@ def _fixup_main_from_path(main_path: str) -> None:
# old_main_modules.append(current_main) # old_main_modules.append(current_main)
main_module = types.ModuleType("__mp_main__") main_module = types.ModuleType("__mp_main__")
main_content = runpy.run_path(main_path, main_content = runpy.run_path(main_path,
run_name="__mp_main__") run_name="__mp_main__") # type: ignore
main_module.__dict__.update(main_content) main_module.__dict__.update(main_content)
sys.modules['__main__'] = sys.modules['__mp_main__'] = main_module sys.modules['__main__'] = sys.modules['__mp_main__'] = main_module

View File

@ -4,6 +4,7 @@ Root actor runtime ignition(s).
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from functools import partial from functools import partial
import importlib import importlib
import os
from typing import Tuple, Optional, List, Any from typing import Tuple, Optional, List, Any
import typing import typing
import warnings import warnings
@ -55,6 +56,11 @@ async def open_root_actor(
"""Async entry point for ``tractor``. """Async entry point for ``tractor``.
""" """
# Override the global debugger hook to make it play nice with
# ``trio``, see:
# https://github.com/python-trio/trio/issues/1155#issuecomment-742964018
os.environ['PYTHONBREAKPOINT'] = 'tractor._debug._set_trace'
# 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