Skip to content

Commit

Permalink
Add mention subactor uid during locking
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Oct 7, 2020
1 parent abf8bb2 commit 0711208
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tractor/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from async_generator import aclosing
import tractor
import trio
# from trio.testing import wait_all_tasks_blocked
from trio.testing import wait_all_tasks_blocked

from .log import get_logger
from . import _state
Expand Down Expand Up @@ -117,19 +117,19 @@ def set_quit(self):


@asynccontextmanager
async def _acquire_debug_lock():
async def _acquire_debug_lock(uid: Tuple[str, str]) -> None:
"""Acquire a actor local FIFO lock meant to mutex entry to a local
debugger entry point to avoid tty clobbering by multiple processes.
"""
task_name = trio.lowlevel.current_task()
try:
log.error(f"TTY BEING ACQUIRED by {task_name}")
log.error(f"TTY BEING ACQUIRED by {task_name}:{uid}")
await _debug_lock.acquire()
log.error(f"TTY lock acquired by {task_name}")
log.error(f"TTY lock acquired by {task_name}:{uid}")
yield
finally:
_debug_lock.release()
log.error(f"TTY lock released by {task_name}")
log.error(f"TTY lock released by {task_name}:{uid}")


def handler(signum, frame):
Expand Down Expand Up @@ -162,7 +162,7 @@ async def _hijack_stdin_relay_to_child(
# TODO: when we get to true remote debugging
# this will deliver stdin data
log.warning(f"Actor {subactor_uid} is WAITING on stdin hijack lock")
async with _acquire_debug_lock():
async with _acquire_debug_lock(subactor_uid):
log.warning(f"Actor {subactor_uid} ACQUIRED stdin hijack lock")

# with _disable_sigint():
Expand Down Expand Up @@ -266,9 +266,10 @@ async def _bp():

# block here one (at the appropriate frame *up* where
# ``breakpoint()`` was awaited and begin handling stdio
log.debug("Entering the synchronous world of the debugger")
log.debug("Entering the synchronous world of pdb")
debug_func(actor)


# user code **must** await this!
return _bp()

Expand All @@ -288,7 +289,7 @@ def _set_trace(actor):


def _post_mortem(actor):
log.error(f"\nAttaching to pdb in crashed actor: {actor.uid}\n")
log.critical(f"\nAttaching to pdb in crashed actor: {actor.uid}\n")
# custom Pdb post-mortem entry
pdbpp.xpm(Pdb=PdbwTeardown)

Expand Down

0 comments on commit 0711208

Please sign in to comment.