forked from goodboy/tractor
Cleanups and more comments
parent
68773d51fd
commit
f9ef3fc5de
|
@ -3,7 +3,7 @@ Multi-core debugging for da peeps!
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Awaitable, Tuple
|
from typing import Awaitable, Tuple, Optional, Callable
|
||||||
|
|
||||||
from async_generator import aclosing
|
from async_generator import aclosing
|
||||||
import tractor
|
import tractor
|
||||||
|
@ -27,27 +27,8 @@ log = get_logger(__name__)
|
||||||
__all__ = ['breakpoint', 'post_mortem']
|
__all__ = ['breakpoint', 'post_mortem']
|
||||||
|
|
||||||
|
|
||||||
# TODO: is there some way to determine this programatically?
|
# placeholder for function to set a ``trio.Event``
|
||||||
_pdb_exit_patterns = tuple(
|
_pdb_release_hook: Optional[Callable] = None
|
||||||
str.encode(patt + "\n") for patt in ('c', 'cont', 'continue', 'q', 'quit')
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
_pdb_release_hook = None
|
|
||||||
|
|
||||||
|
|
||||||
class PdbwTeardown(pdbpp.Pdb):
|
|
||||||
"""Add teardown hooks to the regular ``pdbpp.Pdb``.
|
|
||||||
"""
|
|
||||||
# TODO: figure out how to dissallow recursive .set_trace() entry
|
|
||||||
# since that'll cause deadlock for us.
|
|
||||||
def set_continue(self):
|
|
||||||
super().set_continue()
|
|
||||||
self.config.teardown(self)
|
|
||||||
|
|
||||||
def set_quit(self):
|
|
||||||
super().set_quit()
|
|
||||||
self.config.teardown(self)
|
|
||||||
|
|
||||||
|
|
||||||
class TractorConfig(pdbpp.DefaultConfig):
|
class TractorConfig(pdbpp.DefaultConfig):
|
||||||
|
@ -59,13 +40,32 @@ class TractorConfig(pdbpp.DefaultConfig):
|
||||||
_pdb_release_hook(_pdb)
|
_pdb_release_hook(_pdb)
|
||||||
|
|
||||||
|
|
||||||
|
class PdbwTeardown(pdbpp.Pdb):
|
||||||
|
"""Add teardown hooks to the regular ``pdbpp.Pdb``.
|
||||||
|
"""
|
||||||
# override the pdbpp config with our coolio one
|
# override the pdbpp config with our coolio one
|
||||||
pdbpp.Pdb.DefaultConfig = TractorConfig
|
DefaultConfig = TractorConfig
|
||||||
|
|
||||||
|
# TODO: figure out how to dissallow recursive .set_trace() entry
|
||||||
|
# since that'll cause deadlock for us.
|
||||||
|
def set_continue(self):
|
||||||
|
super().set_continue()
|
||||||
|
self.config.teardown(self)
|
||||||
|
|
||||||
|
def set_quit(self):
|
||||||
|
super().set_quit()
|
||||||
|
self.config.teardown(self)
|
||||||
|
|
||||||
|
|
||||||
# TODO: will be needed whenever we get to true remote debugging.
|
# TODO: will be needed whenever we get to true remote debugging.
|
||||||
# XXX see https://github.com/goodboy/tractor/issues/130
|
# XXX see https://github.com/goodboy/tractor/issues/130
|
||||||
|
|
||||||
|
# # TODO: is there some way to determine this programatically?
|
||||||
|
# _pdb_exit_patterns = tuple(
|
||||||
|
# str.encode(patt + "\n") for patt in (
|
||||||
|
# 'c', 'cont', 'continue', 'q', 'quit')
|
||||||
|
# )
|
||||||
|
|
||||||
# def subactoruid2proc(
|
# def subactoruid2proc(
|
||||||
# actor: 'Actor', # noqa
|
# actor: 'Actor', # noqa
|
||||||
# uid: Tuple[str, str]
|
# uid: Tuple[str, str]
|
||||||
|
@ -170,17 +170,16 @@ def _breakpoint(debug_func) -> Awaitable[None]:
|
||||||
_pdb_release_hook = unlock
|
_pdb_release_hook = unlock
|
||||||
|
|
||||||
async def _bp():
|
async def _bp():
|
||||||
# this must be awaited by caller
|
# this **must** be awaited by the caller and is done using the
|
||||||
await actor._root_nursery.start(
|
# root nursery so that the debugger can continue to run without
|
||||||
wait_for_parent_stdin_hijack
|
# being restricted by the scope of a new task nursery.
|
||||||
)
|
await actor._root_nursery.start(wait_for_parent_stdin_hijack)
|
||||||
|
|
||||||
# block here one frame up where ``breakpoint()``
|
# block here one (at the appropriate frame *up* where
|
||||||
# was awaited and begin handling stdin
|
# ``breakpoint()`` was awaited and begin handling stdio
|
||||||
debug_func(actor)
|
debug_func(actor)
|
||||||
|
|
||||||
# return wait_for_parent_stdin_hijack()
|
return _bp() # user code **must** await this!
|
||||||
return _bp()
|
|
||||||
|
|
||||||
|
|
||||||
def _set_trace(actor):
|
def _set_trace(actor):
|
||||||
|
|
Loading…
Reference in New Issue