-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
End the pdb
SIGINT handling madness
#170
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -767,8 +767,8 @@ async def _async_main( | |
finally: | ||
log.info("Root nursery complete") | ||
|
||
# tear down all lifetime contexts | ||
# api idea: ``tractor.open_context()`` | ||
# tear down all lifetime contexts if not in guest mode | ||
# XXX: should this just be in the entrypoint? | ||
log.warning("Closing all actor lifetime contexts") | ||
self._lifetime_stack.close() | ||
|
||
|
@@ -821,7 +821,7 @@ async def _serve_forever( | |
self._server_down = trio.Event() | ||
try: | ||
async with trio.open_nursery() as server_n: | ||
listeners: List[trio.abc.Listener] = await server_n.start( | ||
l: List[trio.abc.Listener] = await server_n.start( | ||
partial( | ||
trio.serve_tcp, | ||
self._stream_handler, | ||
|
@@ -832,9 +832,10 @@ async def _serve_forever( | |
host=accept_host, | ||
) | ||
) | ||
log.debug("Started tcp server(s) on" # type: ignore | ||
f" {[l.socket for l in listeners]}") | ||
self._listeners.extend(listeners) | ||
log.debug( | ||
"Started tcp server(s) on" | ||
f" {[getattr(l, 'socket', 'unknown socket') for l in l]}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just |
||
self._listeners.extend(l) | ||
task_status.started(server_n) | ||
finally: | ||
# signal the server is down since nursery above terminated | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,10 @@ | |
from functools import partial | ||
from contextlib import asynccontextmanager | ||
from typing import Awaitable, Tuple, Optional, Callable, AsyncIterator | ||
# import signal | ||
|
||
from async_generator import aclosing | ||
import tractor | ||
import trio | ||
from trio.testing import wait_all_tasks_blocked | ||
|
||
from .log import get_logger | ||
from . import _state | ||
|
@@ -132,19 +130,6 @@ async def _acquire_debug_lock(uid: Tuple[str, str]) -> AsyncIterator[None]: | |
log.error(f"TTY lock released by {task_name}:{uid}") | ||
|
||
|
||
def handler(signum, frame): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out we can just keep |
||
"""Block SIGINT while in debug to avoid deadlocks with cancellation. | ||
""" | ||
print( | ||
"tractor ignores SIGINT while in debug mode\n" | ||
"If you have a special need for it please open an issue.\n" | ||
) | ||
|
||
|
||
# don't allow those stdlib mofos to mess with sigint handler | ||
pdbpp.pdb.Pdb.sigint_handler = handler | ||
|
||
|
||
# @contextmanager | ||
# def _disable_sigint(): | ||
# try: | ||
|
@@ -269,14 +254,29 @@ async def _bp(): | |
log.debug("Entering the synchronous world of pdb") | ||
debug_func(actor) | ||
|
||
|
||
# user code **must** await this! | ||
return _bp() | ||
|
||
|
||
def _mk_pdb(): | ||
# XXX: setting these flags on the pdb instance are absolutely | ||
# critical to having ctrl-c work in the ``trio`` standard way! | ||
# The stdlib's pdb supports entering the current sync frame | ||
# on a SIGINT, with ``trio`` we pretty much never want this | ||
# and we did we can handle it in the ``tractor`` task runtime. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be and if we did.. |
||
|
||
pdb = PdbwTeardown() | ||
pdb.allow_kbdint = True | ||
pdb.nosigint = True | ||
|
||
return pdb | ||
|
||
|
||
def _set_trace(actor): | ||
log.critical(f"\nAttaching pdb to actor: {actor.uid}\n") | ||
PdbwTeardown().set_trace( | ||
|
||
pdb = _mk_pdb() | ||
pdb.set_trace( | ||
# start 2 levels up in user code | ||
frame=sys._getframe().f_back.f_back, | ||
) | ||
|
@@ -290,8 +290,10 @@ def _set_trace(actor): | |
|
||
def _post_mortem(actor): | ||
log.critical(f"\nAttaching to pdb in crashed actor: {actor.uid}\n") | ||
pdb = _mk_pdb() | ||
|
||
# custom Pdb post-mortem entry | ||
pdbpp.xpm(Pdb=PdbwTeardown) | ||
pdbpp.xpm(Pdb=lambda: pdb) | ||
|
||
|
||
post_mortem = partial( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are probably superfluous (and maybe should be
.debug()
) but figured can't hurt atm. Likely we'll throttle back logging noise before first.dev0
.