forked from goodboy/tractor
Change lock helper to take an actor uid tuple
parent
6f5c35dd1b
commit
fa317d1600
|
@ -6,7 +6,13 @@ import bdb
|
||||||
import sys
|
import sys
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from contextlib import asynccontextmanager as acm
|
from contextlib import asynccontextmanager as acm
|
||||||
from typing import Tuple, Optional, Callable, AsyncIterator
|
from typing import (
|
||||||
|
Tuple,
|
||||||
|
Optional,
|
||||||
|
Callable,
|
||||||
|
AsyncIterator,
|
||||||
|
AsyncGenerator,
|
||||||
|
)
|
||||||
|
|
||||||
import tractor
|
import tractor
|
||||||
import trio
|
import trio
|
||||||
|
@ -281,7 +287,7 @@ async def _hijack_stdin_for_child(
|
||||||
|
|
||||||
|
|
||||||
async def wait_for_parent_stdin_hijack(
|
async def wait_for_parent_stdin_hijack(
|
||||||
actor: 'Actor', # noqa
|
actor_uid: Tuple[str, str],
|
||||||
task_status: TaskStatus[trio.CancelScope] = trio.TASK_STATUS_IGNORED
|
task_status: TaskStatus[trio.CancelScope] = trio.TASK_STATUS_IGNORED
|
||||||
):
|
):
|
||||||
'''
|
'''
|
||||||
|
@ -307,7 +313,7 @@ async def wait_for_parent_stdin_hijack(
|
||||||
async with portal.open_context(
|
async with portal.open_context(
|
||||||
|
|
||||||
tractor._debug._hijack_stdin_for_child,
|
tractor._debug._hijack_stdin_for_child,
|
||||||
subactor_uid=actor.uid,
|
subactor_uid=actor_uid,
|
||||||
|
|
||||||
) as (ctx, val):
|
) as (ctx, val):
|
||||||
|
|
||||||
|
@ -319,6 +325,7 @@ async def wait_for_parent_stdin_hijack(
|
||||||
task_status.started(cs)
|
task_status.started(cs)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
assert _local_pdb_complete
|
||||||
await _local_pdb_complete.wait()
|
await _local_pdb_complete.wait()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
@ -333,10 +340,10 @@ async def wait_for_parent_stdin_hijack(
|
||||||
log.warning('Root actor cancelled debug lock')
|
log.warning('Root actor cancelled debug lock')
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
log.debug(f"Exiting debugger for actor {actor.uid}")
|
log.debug(f"Exiting debugger for actor {actor_uid}")
|
||||||
global _local_task_in_debug
|
global _local_task_in_debug
|
||||||
_local_task_in_debug = None
|
_local_task_in_debug = None
|
||||||
log.debug(f"Child {actor.uid} released parent stdio lock")
|
log.debug(f"Child {actor_uid} released parent stdio lock")
|
||||||
|
|
||||||
|
|
||||||
async def _breakpoint(
|
async def _breakpoint(
|
||||||
|
@ -545,8 +552,8 @@ async def _maybe_enter_pm(err):
|
||||||
|
|
||||||
@acm
|
@acm
|
||||||
async def acquire_debug_lock(
|
async def acquire_debug_lock(
|
||||||
subactor: 'Actor', # noqa
|
subactor_uid: Tuple[str, str]
|
||||||
) -> None:
|
) -> AsyncGenerator[None, tuple]:
|
||||||
'''
|
'''
|
||||||
Grab root's debug lock on entry, release on exit.
|
Grab root's debug lock on entry, release on exit.
|
||||||
|
|
||||||
|
@ -554,9 +561,9 @@ async def acquire_debug_lock(
|
||||||
async with trio.open_nursery() as n:
|
async with trio.open_nursery() as n:
|
||||||
cs = await n.start(
|
cs = await n.start(
|
||||||
wait_for_parent_stdin_hijack,
|
wait_for_parent_stdin_hijack,
|
||||||
subactor,
|
subactor_uid,
|
||||||
)
|
)
|
||||||
yield
|
yield None
|
||||||
cs.cancel()
|
cs.cancel()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -249,7 +249,7 @@ async def new_proc(
|
||||||
if is_root_process():
|
if is_root_process():
|
||||||
await maybe_wait_for_debugger()
|
await maybe_wait_for_debugger()
|
||||||
else:
|
else:
|
||||||
async with acquire_debug_lock():
|
async with acquire_debug_lock(uid):
|
||||||
# soft wait on the proc to terminate
|
# soft wait on the proc to terminate
|
||||||
with trio.move_on_after(0.5):
|
with trio.move_on_after(0.5):
|
||||||
await proc.wait()
|
await proc.wait()
|
||||||
|
@ -315,7 +315,7 @@ async def new_proc(
|
||||||
if cancel_during_spawn:
|
if cancel_during_spawn:
|
||||||
|
|
||||||
# Try again to avoid TTY clobbering.
|
# Try again to avoid TTY clobbering.
|
||||||
async with acquire_debug_lock():
|
async with acquire_debug_lock(uid):
|
||||||
with trio.move_on_after(0.5):
|
with trio.move_on_after(0.5):
|
||||||
await proc.wait()
|
await proc.wait()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue