Compare commits
No commits in common. "db58f6e1b598f4f37ef047f920ce263eeed5a5f9" and "e269aa3751277e31cc647ce68048481f8ae31cb7" have entirely different histories.
db58f6e1b5
...
e269aa3751
|
@ -10,7 +10,6 @@ TODO:
|
||||||
- wonder if any of it'll work on OS X?
|
- wonder if any of it'll work on OS X?
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from functools import partial
|
|
||||||
import itertools
|
import itertools
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import platform
|
import platform
|
||||||
|
@ -27,10 +26,6 @@ from pexpect.exceptions import (
|
||||||
from tractor._testing import (
|
from tractor._testing import (
|
||||||
examples_dir,
|
examples_dir,
|
||||||
)
|
)
|
||||||
from tractor.devx._debug import (
|
|
||||||
_pause_msg,
|
|
||||||
_crash_msg,
|
|
||||||
)
|
|
||||||
from conftest import (
|
from conftest import (
|
||||||
_ci_env,
|
_ci_env,
|
||||||
)
|
)
|
||||||
|
@ -128,52 +123,20 @@ def expect(
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def in_prompt_msg(
|
|
||||||
prompt: str,
|
|
||||||
parts: list[str],
|
|
||||||
|
|
||||||
pause_on_false: bool = False,
|
|
||||||
print_prompt_on_false: bool = True,
|
|
||||||
|
|
||||||
) -> bool:
|
|
||||||
'''
|
|
||||||
Predicate check if (the prompt's) std-streams output has all
|
|
||||||
`str`-parts in it.
|
|
||||||
|
|
||||||
Can be used in test asserts for bulk matching expected
|
|
||||||
log/REPL output for a given `pdb` interact point.
|
|
||||||
|
|
||||||
'''
|
|
||||||
for part in parts:
|
|
||||||
if part not in prompt:
|
|
||||||
|
|
||||||
if pause_on_false:
|
|
||||||
import pdbp
|
|
||||||
pdbp.set_trace()
|
|
||||||
|
|
||||||
if print_prompt_on_false:
|
|
||||||
print(prompt)
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def assert_before(
|
def assert_before(
|
||||||
child,
|
child,
|
||||||
patts: list[str],
|
patts: list[str],
|
||||||
|
|
||||||
**kwargs,
|
|
||||||
|
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
# as in before the prompt end
|
before = str(child.before.decode())
|
||||||
before: str = str(child.before.decode())
|
|
||||||
assert in_prompt_msg(
|
|
||||||
prompt=before,
|
|
||||||
parts=patts,
|
|
||||||
|
|
||||||
**kwargs
|
for patt in patts:
|
||||||
)
|
try:
|
||||||
|
assert patt in before
|
||||||
|
except AssertionError:
|
||||||
|
print(before)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(
|
@pytest.fixture(
|
||||||
|
@ -232,10 +195,7 @@ def test_root_actor_error(spawn, user_in_out):
|
||||||
before = str(child.before.decode())
|
before = str(child.before.decode())
|
||||||
|
|
||||||
# make sure expected logging and error arrives
|
# make sure expected logging and error arrives
|
||||||
assert in_prompt_msg(
|
assert "Attaching to pdb in crashed actor: ('root'" in before
|
||||||
before,
|
|
||||||
[_crash_msg, "('root'"]
|
|
||||||
)
|
|
||||||
assert 'AssertionError' in before
|
assert 'AssertionError' in before
|
||||||
|
|
||||||
# send user command
|
# send user command
|
||||||
|
@ -372,10 +332,7 @@ def test_subactor_error(
|
||||||
child.expect(PROMPT)
|
child.expect(PROMPT)
|
||||||
|
|
||||||
before = str(child.before.decode())
|
before = str(child.before.decode())
|
||||||
assert in_prompt_msg(
|
assert "Attaching to pdb in crashed actor: ('name_error'" in before
|
||||||
before,
|
|
||||||
[_crash_msg, "('name_error'"]
|
|
||||||
)
|
|
||||||
|
|
||||||
if do_next:
|
if do_next:
|
||||||
child.sendline('n')
|
child.sendline('n')
|
||||||
|
@ -396,15 +353,9 @@ def test_subactor_error(
|
||||||
before = str(child.before.decode())
|
before = str(child.before.decode())
|
||||||
|
|
||||||
# root actor gets debugger engaged
|
# root actor gets debugger engaged
|
||||||
assert in_prompt_msg(
|
assert "Attaching to pdb in crashed actor: ('root'" in before
|
||||||
before,
|
|
||||||
[_crash_msg, "('root'"]
|
|
||||||
)
|
|
||||||
# error is a remote error propagated from the subactor
|
# error is a remote error propagated from the subactor
|
||||||
assert in_prompt_msg(
|
assert "RemoteActorError: ('name_error'" in before
|
||||||
before,
|
|
||||||
[_crash_msg, "('name_error'"]
|
|
||||||
)
|
|
||||||
|
|
||||||
# another round
|
# another round
|
||||||
if ctlc:
|
if ctlc:
|
||||||
|
@ -429,10 +380,7 @@ def test_subactor_breakpoint(
|
||||||
child.expect(PROMPT)
|
child.expect(PROMPT)
|
||||||
|
|
||||||
before = str(child.before.decode())
|
before = str(child.before.decode())
|
||||||
assert in_prompt_msg(
|
assert "Attaching pdb to actor: ('breakpoint_forever'" in before
|
||||||
before,
|
|
||||||
[_pause_msg, "('breakpoint_forever'"]
|
|
||||||
)
|
|
||||||
|
|
||||||
# do some "next" commands to demonstrate recurrent breakpoint
|
# do some "next" commands to demonstrate recurrent breakpoint
|
||||||
# entries
|
# entries
|
||||||
|
@ -448,10 +396,7 @@ def test_subactor_breakpoint(
|
||||||
child.sendline('continue')
|
child.sendline('continue')
|
||||||
child.expect(PROMPT)
|
child.expect(PROMPT)
|
||||||
before = str(child.before.decode())
|
before = str(child.before.decode())
|
||||||
assert in_prompt_msg(
|
assert "Attaching pdb to actor: ('breakpoint_forever'" in before
|
||||||
before,
|
|
||||||
[_pause_msg, "('breakpoint_forever'"]
|
|
||||||
)
|
|
||||||
|
|
||||||
if ctlc:
|
if ctlc:
|
||||||
do_ctlc(child)
|
do_ctlc(child)
|
||||||
|
@ -496,10 +441,7 @@ def test_multi_subactors(
|
||||||
child.expect(PROMPT)
|
child.expect(PROMPT)
|
||||||
|
|
||||||
before = str(child.before.decode())
|
before = str(child.before.decode())
|
||||||
assert in_prompt_msg(
|
assert "Attaching pdb to actor: ('breakpoint_forever'" in before
|
||||||
before,
|
|
||||||
[_pause_msg, "('breakpoint_forever'"]
|
|
||||||
)
|
|
||||||
|
|
||||||
if ctlc:
|
if ctlc:
|
||||||
do_ctlc(child)
|
do_ctlc(child)
|
||||||
|
@ -519,10 +461,7 @@ def test_multi_subactors(
|
||||||
# first name_error failure
|
# first name_error failure
|
||||||
child.expect(PROMPT)
|
child.expect(PROMPT)
|
||||||
before = str(child.before.decode())
|
before = str(child.before.decode())
|
||||||
assert in_prompt_msg(
|
assert "Attaching to pdb in crashed actor: ('name_error'" in before
|
||||||
before,
|
|
||||||
[_crash_msg, "('name_error'"]
|
|
||||||
)
|
|
||||||
assert "NameError" in before
|
assert "NameError" in before
|
||||||
|
|
||||||
if ctlc:
|
if ctlc:
|
||||||
|
@ -548,10 +487,7 @@ def test_multi_subactors(
|
||||||
child.sendline('c')
|
child.sendline('c')
|
||||||
child.expect(PROMPT)
|
child.expect(PROMPT)
|
||||||
before = str(child.before.decode())
|
before = str(child.before.decode())
|
||||||
assert in_prompt_msg(
|
assert "Attaching pdb to actor: ('breakpoint_forever'" in before
|
||||||
before,
|
|
||||||
[_pause_msg, "('breakpoint_forever'"]
|
|
||||||
)
|
|
||||||
|
|
||||||
if ctlc:
|
if ctlc:
|
||||||
do_ctlc(child)
|
do_ctlc(child)
|
||||||
|
@ -591,21 +527,17 @@ def test_multi_subactors(
|
||||||
child.expect(PROMPT)
|
child.expect(PROMPT)
|
||||||
before = str(child.before.decode())
|
before = str(child.before.decode())
|
||||||
|
|
||||||
assert_before(
|
assert_before(child, [
|
||||||
child, [
|
# debugger attaches to root
|
||||||
# debugger attaches to root
|
"Attaching to pdb in crashed actor: ('root'",
|
||||||
# "Attaching to pdb in crashed actor: ('root'",
|
|
||||||
_crash_msg,
|
|
||||||
"('root'",
|
|
||||||
|
|
||||||
# expect a multierror with exceptions for each sub-actor
|
# expect a multierror with exceptions for each sub-actor
|
||||||
"RemoteActorError: ('breakpoint_forever'",
|
"RemoteActorError: ('breakpoint_forever'",
|
||||||
"RemoteActorError: ('name_error'",
|
"RemoteActorError: ('name_error'",
|
||||||
"RemoteActorError: ('spawn_error'",
|
"RemoteActorError: ('spawn_error'",
|
||||||
"RemoteActorError: ('name_error_1'",
|
"RemoteActorError: ('name_error_1'",
|
||||||
'bdb.BdbQuit',
|
'bdb.BdbQuit',
|
||||||
]
|
])
|
||||||
)
|
|
||||||
|
|
||||||
if ctlc:
|
if ctlc:
|
||||||
do_ctlc(child)
|
do_ctlc(child)
|
||||||
|
@ -642,22 +574,15 @@ def test_multi_daemon_subactors(
|
||||||
# the root's tty lock first so anticipate either crash
|
# the root's tty lock first so anticipate either crash
|
||||||
# message on the first entry.
|
# message on the first entry.
|
||||||
|
|
||||||
bp_forev_parts = [_pause_msg, "('bp_forever'"]
|
bp_forever_msg = "Attaching pdb to actor: ('bp_forever'"
|
||||||
bp_forev_in_msg = partial(
|
|
||||||
in_prompt_msg,
|
|
||||||
parts=bp_forev_parts,
|
|
||||||
)
|
|
||||||
|
|
||||||
name_error_msg = "NameError: name 'doggypants' is not defined"
|
name_error_msg = "NameError: name 'doggypants' is not defined"
|
||||||
name_error_parts = [name_error_msg]
|
|
||||||
|
|
||||||
before = str(child.before.decode())
|
before = str(child.before.decode())
|
||||||
|
if bp_forever_msg in before:
|
||||||
if bp_forev_in_msg(prompt=before):
|
next_msg = name_error_msg
|
||||||
next_parts = name_error_parts
|
|
||||||
|
|
||||||
elif name_error_msg in before:
|
elif name_error_msg in before:
|
||||||
next_parts = bp_forev_parts
|
next_msg = bp_forever_msg
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("Neither log msg was found !?")
|
raise ValueError("Neither log msg was found !?")
|
||||||
|
@ -674,10 +599,7 @@ def test_multi_daemon_subactors(
|
||||||
|
|
||||||
child.sendline('c')
|
child.sendline('c')
|
||||||
child.expect(PROMPT)
|
child.expect(PROMPT)
|
||||||
assert_before(
|
assert_before(child, [next_msg])
|
||||||
child,
|
|
||||||
next_parts,
|
|
||||||
)
|
|
||||||
|
|
||||||
# XXX: hooray the root clobbering the child here was fixed!
|
# XXX: hooray the root clobbering the child here was fixed!
|
||||||
# IMO, this demonstrates the true power of SC system design.
|
# IMO, this demonstrates the true power of SC system design.
|
||||||
|
@ -701,15 +623,9 @@ def test_multi_daemon_subactors(
|
||||||
child.expect(PROMPT)
|
child.expect(PROMPT)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
assert_before(
|
assert_before(child, [bp_forever_msg])
|
||||||
child,
|
|
||||||
bp_forev_parts,
|
|
||||||
)
|
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
assert_before(
|
assert_before(child, [name_error_msg])
|
||||||
child,
|
|
||||||
name_error_parts,
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if ctlc:
|
if ctlc:
|
||||||
|
@ -721,10 +637,7 @@ def test_multi_daemon_subactors(
|
||||||
|
|
||||||
child.sendline('c')
|
child.sendline('c')
|
||||||
child.expect(PROMPT)
|
child.expect(PROMPT)
|
||||||
assert_before(
|
assert_before(child, [name_error_msg])
|
||||||
child,
|
|
||||||
name_error_parts,
|
|
||||||
)
|
|
||||||
|
|
||||||
# wait for final error in root
|
# wait for final error in root
|
||||||
# where it crashs with boxed error
|
# where it crashs with boxed error
|
||||||
|
@ -734,7 +647,7 @@ def test_multi_daemon_subactors(
|
||||||
child.expect(PROMPT)
|
child.expect(PROMPT)
|
||||||
assert_before(
|
assert_before(
|
||||||
child,
|
child,
|
||||||
bp_forev_parts
|
[bp_forever_msg]
|
||||||
)
|
)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
break
|
break
|
||||||
|
@ -743,9 +656,7 @@ def test_multi_daemon_subactors(
|
||||||
child,
|
child,
|
||||||
[
|
[
|
||||||
# boxed error raised in root task
|
# boxed error raised in root task
|
||||||
# "Attaching to pdb in crashed actor: ('root'",
|
"Attaching to pdb in crashed actor: ('root'",
|
||||||
_crash_msg,
|
|
||||||
"('root'",
|
|
||||||
"_exceptions.RemoteActorError: ('name_error'",
|
"_exceptions.RemoteActorError: ('name_error'",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -859,7 +770,7 @@ def test_multi_nested_subactors_error_through_nurseries(
|
||||||
|
|
||||||
child = spawn('multi_nested_subactors_error_up_through_nurseries')
|
child = spawn('multi_nested_subactors_error_up_through_nurseries')
|
||||||
|
|
||||||
# timed_out_early: bool = False
|
timed_out_early: bool = False
|
||||||
|
|
||||||
for send_char in itertools.cycle(['c', 'q']):
|
for send_char in itertools.cycle(['c', 'q']):
|
||||||
try:
|
try:
|
||||||
|
@ -960,14 +871,11 @@ def test_root_nursery_cancels_before_child_releases_tty_lock(
|
||||||
|
|
||||||
if not timed_out_early:
|
if not timed_out_early:
|
||||||
before = str(child.before.decode())
|
before = str(child.before.decode())
|
||||||
assert_before(
|
assert_before(child, [
|
||||||
child,
|
"tractor._exceptions.RemoteActorError: ('spawner0'",
|
||||||
[
|
"tractor._exceptions.RemoteActorError: ('name_error'",
|
||||||
"tractor._exceptions.RemoteActorError: ('spawner0'",
|
"NameError: name 'doggypants' is not defined",
|
||||||
"tractor._exceptions.RemoteActorError: ('name_error'",
|
])
|
||||||
"NameError: name 'doggypants' is not defined",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_root_cancels_child_context_during_startup(
|
def test_root_cancels_child_context_during_startup(
|
||||||
|
@ -1001,10 +909,8 @@ def test_different_debug_mode_per_actor(
|
||||||
|
|
||||||
# only one actor should enter the debugger
|
# only one actor should enter the debugger
|
||||||
before = str(child.before.decode())
|
before = str(child.before.decode())
|
||||||
assert in_prompt_msg(
|
assert "Attaching to pdb in crashed actor: ('debugged_boi'" in before
|
||||||
before,
|
assert "RuntimeError" in before
|
||||||
[_crash_msg, "('debugged_boi'", "RuntimeError"],
|
|
||||||
)
|
|
||||||
|
|
||||||
if ctlc:
|
if ctlc:
|
||||||
do_ctlc(child)
|
do_ctlc(child)
|
||||||
|
|
|
@ -551,14 +551,13 @@ async def trio_proc(
|
||||||
with trio.move_on_after(0.5):
|
with trio.move_on_after(0.5):
|
||||||
await proc.wait()
|
await proc.wait()
|
||||||
|
|
||||||
|
log.pdb(
|
||||||
|
'Delaying subproc reaper while debugger locked..'
|
||||||
|
)
|
||||||
await maybe_wait_for_debugger(
|
await maybe_wait_for_debugger(
|
||||||
child_in_debug=_runtime_vars.get(
|
child_in_debug=_runtime_vars.get(
|
||||||
'_debug_mode', False
|
'_debug_mode', False
|
||||||
),
|
),
|
||||||
header_msg=(
|
|
||||||
'Delaying subproc reaper while debugger locked..\n'
|
|
||||||
),
|
|
||||||
|
|
||||||
# TODO: need a diff value then default?
|
# TODO: need a diff value then default?
|
||||||
# poll_steps=9999999,
|
# poll_steps=9999999,
|
||||||
)
|
)
|
||||||
|
|
|
@ -21,17 +21,27 @@ and working with/on the actor runtime.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from ._debug import (
|
from ._debug import (
|
||||||
maybe_wait_for_debugger as maybe_wait_for_debugger,
|
maybe_wait_for_debugger,
|
||||||
acquire_debug_lock as acquire_debug_lock,
|
acquire_debug_lock,
|
||||||
breakpoint as breakpoint,
|
breakpoint,
|
||||||
pause as pause,
|
pause,
|
||||||
pause_from_sync as pause_from_sync,
|
pause_from_sync,
|
||||||
shield_sigint_handler as shield_sigint_handler,
|
shield_sigint_handler,
|
||||||
MultiActorPdb as MultiActorPdb,
|
MultiActorPdb,
|
||||||
open_crash_handler as open_crash_handler,
|
open_crash_handler,
|
||||||
maybe_open_crash_handler as maybe_open_crash_handler,
|
maybe_open_crash_handler,
|
||||||
post_mortem as post_mortem,
|
post_mortem,
|
||||||
)
|
|
||||||
from ._stackscope import (
|
|
||||||
enable_stack_on_sig as enable_stack_on_sig,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'maybe_wait_for_debugger',
|
||||||
|
'acquire_debug_lock',
|
||||||
|
'breakpoint',
|
||||||
|
'pause',
|
||||||
|
'pause_from_sync',
|
||||||
|
'shield_sigint_handler',
|
||||||
|
'MultiActorPdb',
|
||||||
|
'open_crash_handler',
|
||||||
|
'maybe_open_crash_handler',
|
||||||
|
'post_mortem',
|
||||||
|
]
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
# tractor: structured concurrent "actors".
|
# tractor: structured concurrent "actors".
|
||||||
# Copyright 2018-eternity Tyler Goodlet.
|
# Copyright 2018-eternity Tyler Goodlet.
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# modify it under the terms of the GNU Affero General Public License
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
# as published by the Free Software Foundation, either version 3 of
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
# the License, or (at your option) any later version.
|
# (at your option) any later version.
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful, but
|
# This program is distributed in the hope that it will be useful,
|
||||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# Affero General Public License for more details.
|
# GNU Affero General Public License for more details.
|
||||||
|
|
||||||
# You should have received a copy of the GNU Affero General Public
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# License along with this program. If not, see
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
# <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Multi-core debugging for da peeps!
|
Multi-core debugging for da peeps!
|
||||||
|
@ -21,19 +20,18 @@ Multi-core debugging for da peeps!
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import bdb
|
import bdb
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import signal
|
||||||
|
from functools import (
|
||||||
|
partial,
|
||||||
|
cached_property,
|
||||||
|
)
|
||||||
from contextlib import (
|
from contextlib import (
|
||||||
asynccontextmanager as acm,
|
asynccontextmanager as acm,
|
||||||
contextmanager as cm,
|
contextmanager as cm,
|
||||||
nullcontext,
|
nullcontext,
|
||||||
)
|
)
|
||||||
from functools import (
|
|
||||||
partial,
|
|
||||||
cached_property,
|
|
||||||
)
|
|
||||||
import os
|
|
||||||
import signal
|
|
||||||
import sys
|
|
||||||
import traceback
|
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
|
@ -45,7 +43,6 @@ from types import FrameType
|
||||||
import pdbp
|
import pdbp
|
||||||
import tractor
|
import tractor
|
||||||
import trio
|
import trio
|
||||||
from trio.lowlevel import current_task
|
|
||||||
from trio_typing import (
|
from trio_typing import (
|
||||||
TaskStatus,
|
TaskStatus,
|
||||||
# Task,
|
# Task,
|
||||||
|
@ -53,7 +50,6 @@ from trio_typing import (
|
||||||
|
|
||||||
from ..log import get_logger
|
from ..log import get_logger
|
||||||
from .._state import (
|
from .._state import (
|
||||||
current_actor,
|
|
||||||
is_root_process,
|
is_root_process,
|
||||||
debug_mode,
|
debug_mode,
|
||||||
)
|
)
|
||||||
|
@ -95,12 +91,12 @@ class Lock:
|
||||||
# and must be cancelled if this actor is cancelled via IPC
|
# and must be cancelled if this actor is cancelled via IPC
|
||||||
# request-message otherwise deadlocks with the parent actor may
|
# request-message otherwise deadlocks with the parent actor may
|
||||||
# ensure
|
# ensure
|
||||||
_debugger_request_cs: trio.CancelScope|None = None
|
_debugger_request_cs: trio.CancelScope | None = None
|
||||||
|
|
||||||
# NOTE: set only in the root actor for the **local** root spawned task
|
# NOTE: set only in the root actor for the **local** root spawned task
|
||||||
# which has acquired the lock (i.e. this is on the callee side of
|
# which has acquired the lock (i.e. this is on the callee side of
|
||||||
# the `lock_tty_for_child()` context entry).
|
# the `lock_tty_for_child()` context entry).
|
||||||
_root_local_task_cs_in_debug: trio.CancelScope|None = None
|
_root_local_task_cs_in_debug: trio.CancelScope | None = None
|
||||||
|
|
||||||
# actor tree-wide actor uid that supposedly has the tty lock
|
# actor tree-wide actor uid that supposedly has the tty lock
|
||||||
global_actor_in_debug: tuple[str, str] = None
|
global_actor_in_debug: tuple[str, str] = None
|
||||||
|
@ -242,7 +238,7 @@ async def _acquire_debug_lock_from_root_task(
|
||||||
to the ``pdb`` repl.
|
to the ``pdb`` repl.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
task_name: str = current_task().name
|
task_name: str = trio.lowlevel.current_task().name
|
||||||
we_acquired: bool = False
|
we_acquired: bool = False
|
||||||
|
|
||||||
log.runtime(
|
log.runtime(
|
||||||
|
@ -327,7 +323,8 @@ async def lock_tty_for_child(
|
||||||
highly reliable at releasing the mutex complete!
|
highly reliable at releasing the mutex complete!
|
||||||
|
|
||||||
'''
|
'''
|
||||||
task_name: str = current_task().name
|
task_name = trio.lowlevel.current_task().name
|
||||||
|
|
||||||
if tuple(subactor_uid) in Lock._blocked:
|
if tuple(subactor_uid) in Lock._blocked:
|
||||||
log.warning(
|
log.warning(
|
||||||
f'Actor {subactor_uid} is blocked from acquiring debug lock\n'
|
f'Actor {subactor_uid} is blocked from acquiring debug lock\n'
|
||||||
|
@ -410,13 +407,11 @@ async def wait_for_parent_stdin_hijack(
|
||||||
assert val == 'Locked'
|
assert val == 'Locked'
|
||||||
|
|
||||||
async with ctx.open_stream() as stream:
|
async with ctx.open_stream() as stream:
|
||||||
|
# unblock local caller
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# unblock local caller
|
|
||||||
assert Lock.local_pdb_complete
|
assert Lock.local_pdb_complete
|
||||||
task_status.started(cs)
|
task_status.started(cs)
|
||||||
|
|
||||||
# wait for local task to exit and
|
|
||||||
# release the REPL
|
|
||||||
await Lock.local_pdb_complete.wait()
|
await Lock.local_pdb_complete.wait()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
@ -473,7 +468,7 @@ def shield_sigint_handler(
|
||||||
|
|
||||||
uid_in_debug: tuple[str, str] | None = Lock.global_actor_in_debug
|
uid_in_debug: tuple[str, str] | None = Lock.global_actor_in_debug
|
||||||
|
|
||||||
actor = current_actor()
|
actor = tractor.current_actor()
|
||||||
# print(f'{actor.uid} in HANDLER with ')
|
# print(f'{actor.uid} in HANDLER with ')
|
||||||
|
|
||||||
def do_cancel():
|
def do_cancel():
|
||||||
|
@ -612,22 +607,17 @@ def shield_sigint_handler(
|
||||||
# https://github.com/prompt-toolkit/python-prompt-toolkit/blob/c2c6af8a0308f9e5d7c0e28cb8a02963fe0ce07a/prompt_toolkit/patch_stdout.py
|
# https://github.com/prompt-toolkit/python-prompt-toolkit/blob/c2c6af8a0308f9e5d7c0e28cb8a02963fe0ce07a/prompt_toolkit/patch_stdout.py
|
||||||
|
|
||||||
|
|
||||||
_pause_msg: str = 'Attaching to pdb REPL in actor'
|
|
||||||
|
|
||||||
|
|
||||||
def _set_trace(
|
def _set_trace(
|
||||||
actor: tractor.Actor | None = None,
|
actor: tractor.Actor | None = None,
|
||||||
pdb: MultiActorPdb | None = None,
|
pdb: MultiActorPdb | None = None,
|
||||||
shield: bool = False,
|
shield: bool = False,
|
||||||
|
|
||||||
extra_frames_up_when_async: int = 1,
|
|
||||||
):
|
):
|
||||||
__tracebackhide__: bool = True
|
__tracebackhide__: bool = True
|
||||||
actor: tractor.Actor = actor or current_actor()
|
actor: tractor.Actor = actor or tractor.current_actor()
|
||||||
|
|
||||||
# always start 1 level up from THIS in user code.
|
# start 2 levels up in user code
|
||||||
frame: FrameType|None
|
frame: FrameType | None = sys._getframe()
|
||||||
if frame := sys._getframe():
|
if frame:
|
||||||
frame: FrameType = frame.f_back # type: ignore
|
frame: FrameType = frame.f_back # type: ignore
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -635,39 +625,17 @@ def _set_trace(
|
||||||
and (
|
and (
|
||||||
pdb
|
pdb
|
||||||
and actor is not None
|
and actor is not None
|
||||||
)
|
) or shield
|
||||||
# or shield
|
|
||||||
):
|
):
|
||||||
msg: str = _pause_msg
|
|
||||||
if shield:
|
|
||||||
# log.warning(
|
|
||||||
msg = (
|
|
||||||
'\n\n'
|
|
||||||
' ------ - ------\n'
|
|
||||||
'Debugger invoked with `shield=True` so an extra\n'
|
|
||||||
'`trio.CancelScope.__exit__()` frame is shown..\n'
|
|
||||||
'\n'
|
|
||||||
'Try going up one frame to see your pause point!\n'
|
|
||||||
'\n'
|
|
||||||
' SORRY we need to fix this!\n'
|
|
||||||
' ------ - ------\n\n'
|
|
||||||
) + msg
|
|
||||||
|
|
||||||
# pdbp.set_trace()
|
# pdbp.set_trace()
|
||||||
# TODO: maybe print the actor supervion tree up to the
|
log.pdb(f"\nAttaching pdb to actor: {actor.uid}\n")
|
||||||
# root here? Bo
|
|
||||||
log.pdb(
|
|
||||||
f'{msg}\n'
|
|
||||||
'|\n'
|
|
||||||
f'|_ {actor.uid}\n'
|
|
||||||
)
|
|
||||||
# no f!#$&* idea, but when we're in async land
|
# no f!#$&* idea, but when we're in async land
|
||||||
# we need 2x frames up?
|
# we need 2x frames up?
|
||||||
for i in range(extra_frames_up_when_async):
|
frame = frame.f_back
|
||||||
frame: FrameType = frame.f_back
|
# frame = frame.f_back
|
||||||
log.debug(
|
|
||||||
f'Going up frame {i} -> {frame}\n'
|
# if shield:
|
||||||
)
|
# frame = frame.f_back
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pdb, undo_sigint = mk_mpdb()
|
pdb, undo_sigint = mk_mpdb()
|
||||||
|
@ -677,9 +645,10 @@ def _set_trace(
|
||||||
Lock.local_task_in_debug = 'sync'
|
Lock.local_task_in_debug = 'sync'
|
||||||
|
|
||||||
pdb.set_trace(frame=frame)
|
pdb.set_trace(frame=frame)
|
||||||
|
# undo_
|
||||||
|
|
||||||
|
|
||||||
async def _pause(
|
async def pause(
|
||||||
|
|
||||||
debug_func: Callable = _set_trace,
|
debug_func: Callable = _set_trace,
|
||||||
release_lock_signal: trio.Event | None = None,
|
release_lock_signal: trio.Event | None = None,
|
||||||
|
@ -693,22 +662,30 @@ async def _pause(
|
||||||
# be no way to override it?..
|
# be no way to override it?..
|
||||||
# shield: bool = False,
|
# shield: bool = False,
|
||||||
|
|
||||||
shield: bool = False,
|
# TODO:
|
||||||
|
# shield: bool = False
|
||||||
task_status: TaskStatus[trio.Event] = trio.TASK_STATUS_IGNORED
|
task_status: TaskStatus[trio.Event] = trio.TASK_STATUS_IGNORED
|
||||||
|
|
||||||
) -> None:
|
) -> None:
|
||||||
'''
|
'''
|
||||||
Inner impl for `pause()` to avoid the `trio.CancelScope.__exit__()`
|
A pause point (more commonly known as a "breakpoint") interrupt
|
||||||
stack frame when not shielded (since apparently i can't figure out
|
instruction for engaging a blocking debugger instance to
|
||||||
how to hide it using the normal mechanisms..)
|
conduct manual console-based-REPL-interaction from within
|
||||||
|
`tractor`'s async runtime, normally from some single-threaded
|
||||||
|
and currently executing actor-hosted-`trio`-task in some
|
||||||
|
(remote) process.
|
||||||
|
|
||||||
Hopefully we won't need this in the long run.
|
NOTE: we use the semantics "pause" since it better encompasses
|
||||||
|
the entirety of the necessary global-runtime-state-mutation any
|
||||||
|
actor-task must access and lock in order to get full isolated
|
||||||
|
control over the process tree's root TTY:
|
||||||
|
https://en.wikipedia.org/wiki/Breakpoint
|
||||||
|
|
||||||
'''
|
'''
|
||||||
__tracebackhide__: bool = True
|
# __tracebackhide__ = True
|
||||||
actor = current_actor()
|
actor = tractor.current_actor()
|
||||||
pdb, undo_sigint = mk_mpdb()
|
pdb, undo_sigint = mk_mpdb()
|
||||||
task_name: str = trio.lowlevel.current_task().name
|
task_name = trio.lowlevel.current_task().name
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not Lock.local_pdb_complete
|
not Lock.local_pdb_complete
|
||||||
|
@ -716,11 +693,24 @@ async def _pause(
|
||||||
):
|
):
|
||||||
Lock.local_pdb_complete = trio.Event()
|
Lock.local_pdb_complete = trio.Event()
|
||||||
|
|
||||||
|
# if shield:
|
||||||
debug_func = partial(
|
debug_func = partial(
|
||||||
debug_func,
|
debug_func,
|
||||||
|
# shield=shield,
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: need a more robust check for the "root" actor
|
# def _exit(self, *args, **kwargs):
|
||||||
|
# __tracebackhide__: bool = True
|
||||||
|
# super().__exit__(*args, **kwargs)
|
||||||
|
|
||||||
|
# trio.CancelScope.__exit__.__tracebackhide__ = True
|
||||||
|
|
||||||
|
# import types
|
||||||
|
# with trio.CancelScope(shield=shield) as cs:
|
||||||
|
# cs.__exit__ = types.MethodType(_exit, cs)
|
||||||
|
# cs.__exit__.__tracebackhide__ = True
|
||||||
|
|
||||||
|
# TODO: need a more robust check for the "root" actor
|
||||||
if (
|
if (
|
||||||
not is_root_process()
|
not is_root_process()
|
||||||
and actor._parent_chan # a connected child
|
and actor._parent_chan # a connected child
|
||||||
|
@ -808,131 +798,37 @@ async def _pause(
|
||||||
Lock.repl = pdb
|
Lock.repl = pdb
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# TODO: do we want to support using this **just** for the
|
if debug_func is None:
|
||||||
# locking / common code (prolly to help address #320)?
|
|
||||||
#
|
|
||||||
# if debug_func is None:
|
|
||||||
# assert release_lock_signal, (
|
# assert release_lock_signal, (
|
||||||
# 'Must pass `release_lock_signal: trio.Event` if no '
|
# 'Must pass `release_lock_signal: trio.Event` if no '
|
||||||
# 'trace func provided!'
|
# 'trace func provided!'
|
||||||
# )
|
# )
|
||||||
# print(f"{actor.uid} ENTERING WAIT")
|
print(f"{actor.uid} ENTERING WAIT")
|
||||||
|
task_status.started()
|
||||||
|
|
||||||
# with trio.CancelScope(shield=True):
|
# with trio.CancelScope(shield=True):
|
||||||
# await release_lock_signal.wait()
|
# await release_lock_signal.wait()
|
||||||
|
|
||||||
# else:
|
else:
|
||||||
# block here one (at the appropriate frame *up*) where
|
# block here one (at the appropriate frame *up*) where
|
||||||
# ``breakpoint()`` was awaited and begin handling stdio.
|
# ``breakpoint()`` was awaited and begin handling stdio.
|
||||||
log.debug('Entering sync world of the `pdb` REPL..')
|
log.debug("Entering the synchronous world of pdb")
|
||||||
try:
|
debug_func(actor, pdb)
|
||||||
debug_func(
|
|
||||||
actor,
|
|
||||||
pdb,
|
|
||||||
extra_frames_up_when_async=2,
|
|
||||||
shield=shield,
|
|
||||||
)
|
|
||||||
except BaseException:
|
|
||||||
log.exception(
|
|
||||||
'Failed to invoke internal `debug_func = '
|
|
||||||
f'{debug_func.func.__name__}`\n'
|
|
||||||
)
|
|
||||||
raise
|
|
||||||
|
|
||||||
except bdb.BdbQuit:
|
except bdb.BdbQuit:
|
||||||
Lock.release()
|
Lock.release()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except BaseException:
|
# XXX: apparently we can't do this without showing this frame
|
||||||
log.exception(
|
# in the backtrace on first entry to the REPL? Seems like an odd
|
||||||
'Failed to engage debugger via `_pause()` ??\n'
|
# behaviour that should have been fixed by now. This is also why
|
||||||
)
|
# we scrapped all the @cm approaches that were tried previously.
|
||||||
raise
|
# finally:
|
||||||
|
# __tracebackhide__ = True
|
||||||
# XXX: apparently we can't do this without showing this frame
|
# # frame = sys._getframe()
|
||||||
# in the backtrace on first entry to the REPL? Seems like an odd
|
# # last_f = frame.f_back
|
||||||
# behaviour that should have been fixed by now. This is also why
|
# # last_f.f_globals['__tracebackhide__'] = True
|
||||||
# we scrapped all the @cm approaches that were tried previously.
|
# # signal.signal = pdbp.hideframe(signal.signal)
|
||||||
# finally:
|
|
||||||
# __tracebackhide__ = True
|
|
||||||
# # frame = sys._getframe()
|
|
||||||
# # last_f = frame.f_back
|
|
||||||
# # last_f.f_globals['__tracebackhide__'] = True
|
|
||||||
# # signal.signal = pdbp.hideframe(signal.signal)
|
|
||||||
|
|
||||||
|
|
||||||
async def pause(
|
|
||||||
|
|
||||||
debug_func: Callable = _set_trace,
|
|
||||||
release_lock_signal: trio.Event | None = None,
|
|
||||||
|
|
||||||
# TODO: allow caller to pause despite task cancellation,
|
|
||||||
# exactly the same as wrapping with:
|
|
||||||
# with CancelScope(shield=True):
|
|
||||||
# await pause()
|
|
||||||
# => the REMAINING ISSUE is that the scope's .__exit__() frame
|
|
||||||
# is always show in the debugger on entry.. and there seems to
|
|
||||||
# be no way to override it?..
|
|
||||||
# shield: bool = False,
|
|
||||||
|
|
||||||
shield: bool = False,
|
|
||||||
task_status: TaskStatus[trio.Event] = trio.TASK_STATUS_IGNORED
|
|
||||||
|
|
||||||
) -> None:
|
|
||||||
'''
|
|
||||||
A pause point (more commonly known as a "breakpoint") interrupt
|
|
||||||
instruction for engaging a blocking debugger instance to
|
|
||||||
conduct manual console-based-REPL-interaction from within
|
|
||||||
`tractor`'s async runtime, normally from some single-threaded
|
|
||||||
and currently executing actor-hosted-`trio`-task in some
|
|
||||||
(remote) process.
|
|
||||||
|
|
||||||
NOTE: we use the semantics "pause" since it better encompasses
|
|
||||||
the entirety of the necessary global-runtime-state-mutation any
|
|
||||||
actor-task must access and lock in order to get full isolated
|
|
||||||
control over the process tree's root TTY:
|
|
||||||
https://en.wikipedia.org/wiki/Breakpoint
|
|
||||||
|
|
||||||
'''
|
|
||||||
__tracebackhide__: bool = True
|
|
||||||
|
|
||||||
if shield:
|
|
||||||
# NOTE XXX: even hard coding this inside the `class CancelScope:`
|
|
||||||
# doesn't seem to work for me!?
|
|
||||||
# ^ XXX ^
|
|
||||||
|
|
||||||
# def _exit(self, *args, **kwargs):
|
|
||||||
# __tracebackhide__: bool = True
|
|
||||||
# super().__exit__(*args, **kwargs)
|
|
||||||
|
|
||||||
trio.CancelScope.__enter__.__tracebackhide__ = True
|
|
||||||
trio.CancelScope.__exit__.__tracebackhide__ = True
|
|
||||||
|
|
||||||
# import types
|
|
||||||
# with trio.CancelScope(shield=shield) as cs:
|
|
||||||
# cs.__exit__ = types.MethodType(_exit, cs)
|
|
||||||
# cs.__exit__.__tracebackhide__ = True
|
|
||||||
|
|
||||||
with trio.CancelScope(shield=shield) as cs:
|
|
||||||
# setattr(cs.__exit__.__func__, '__tracebackhide__', True)
|
|
||||||
# setattr(cs.__enter__.__func__, '__tracebackhide__', True)
|
|
||||||
|
|
||||||
# NOTE: so the caller can always cancel even if shielded
|
|
||||||
task_status.started(cs)
|
|
||||||
return await _pause(
|
|
||||||
debug_func=debug_func,
|
|
||||||
release_lock_signal=release_lock_signal,
|
|
||||||
shield=True,
|
|
||||||
task_status=task_status,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return await _pause(
|
|
||||||
debug_func=debug_func,
|
|
||||||
release_lock_signal=release_lock_signal,
|
|
||||||
shield=False,
|
|
||||||
task_status=task_status,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: allow pausing from sync code.
|
# TODO: allow pausing from sync code.
|
||||||
|
@ -940,7 +836,7 @@ async def pause(
|
||||||
# runtime aware version which takes care of all .
|
# runtime aware version which takes care of all .
|
||||||
def pause_from_sync() -> None:
|
def pause_from_sync() -> None:
|
||||||
print("ENTER SYNC PAUSE")
|
print("ENTER SYNC PAUSE")
|
||||||
actor: tractor.Actor = current_actor(
|
actor: tractor.Actor = tractor.current_actor(
|
||||||
err_on_no_runtime=False,
|
err_on_no_runtime=False,
|
||||||
)
|
)
|
||||||
if actor:
|
if actor:
|
||||||
|
@ -1011,18 +907,9 @@ async def breakpoint(**kwargs):
|
||||||
await pause(**kwargs)
|
await pause(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
_crash_msg: str = (
|
|
||||||
'Attaching to pdb REPL in crashed actor'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _post_mortem(
|
def _post_mortem(
|
||||||
actor: tractor.Actor,
|
actor: tractor.Actor,
|
||||||
pdb: MultiActorPdb,
|
pdb: MultiActorPdb,
|
||||||
shield: bool = False,
|
|
||||||
|
|
||||||
# only for compat with `._set_trace()`..
|
|
||||||
extra_frames_up_when_async=0,
|
|
||||||
|
|
||||||
) -> None:
|
) -> None:
|
||||||
'''
|
'''
|
||||||
|
@ -1030,28 +917,20 @@ def _post_mortem(
|
||||||
debugger instance.
|
debugger instance.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
# TODO: print the actor supervion tree up to the root
|
log.pdb(f"\nAttaching to pdb in crashed actor: {actor.uid}\n")
|
||||||
# here! Bo
|
|
||||||
log.pdb(
|
|
||||||
f'{_crash_msg}\n'
|
|
||||||
'|\n'
|
|
||||||
f'|_ {actor.uid}\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
# TODO: only replacing this to add the
|
# TODO: you need ``pdbpp`` master (at least this commit
|
||||||
# `end=''` to the print XD
|
# https://github.com/pdbpp/pdbpp/commit/b757794857f98d53e3ebbe70879663d7d843a6c2)
|
||||||
# pdbp.xpm(Pdb=lambda: pdb)
|
# to fix this and avoid the hang it causes. See issue:
|
||||||
info = sys.exc_info()
|
# https://github.com/pdbpp/pdbpp/issues/480
|
||||||
print(traceback.format_exc(), end='')
|
# TODO: help with a 3.10+ major release if/when it arrives.
|
||||||
pdbp.post_mortem(
|
|
||||||
t=info[2],
|
pdbp.xpm(Pdb=lambda: pdb)
|
||||||
Pdb=lambda: pdb,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
post_mortem = partial(
|
post_mortem = partial(
|
||||||
pause,
|
pause,
|
||||||
debug_func=_post_mortem,
|
_post_mortem,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1092,10 +971,9 @@ async def acquire_debug_lock(
|
||||||
'''
|
'''
|
||||||
Grab root's debug lock on entry, release on exit.
|
Grab root's debug lock on entry, release on exit.
|
||||||
|
|
||||||
This helper is for actor's who don't actually need to acquired
|
This helper is for actor's who don't actually need
|
||||||
the debugger but want to wait until the lock is free in the
|
to acquired the debugger but want to wait until the
|
||||||
process-tree root such that they don't clobber an ongoing pdb
|
lock is free in the process-tree root.
|
||||||
REPL session in some peer or child!
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
if not debug_mode():
|
if not debug_mode():
|
||||||
|
@ -1116,18 +994,14 @@ async def maybe_wait_for_debugger(
|
||||||
poll_delay: float = 0.1,
|
poll_delay: float = 0.1,
|
||||||
child_in_debug: bool = False,
|
child_in_debug: bool = False,
|
||||||
|
|
||||||
header_msg: str = '',
|
) -> None:
|
||||||
|
|
||||||
) -> bool: # was locked and we polled?
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not debug_mode()
|
not debug_mode()
|
||||||
and not child_in_debug
|
and not child_in_debug
|
||||||
):
|
):
|
||||||
return False
|
return
|
||||||
|
|
||||||
|
|
||||||
msg: str = header_msg
|
|
||||||
if (
|
if (
|
||||||
is_root_process()
|
is_root_process()
|
||||||
):
|
):
|
||||||
|
@ -1137,98 +1011,45 @@ async def maybe_wait_for_debugger(
|
||||||
# will make the pdb repl unusable.
|
# will make the pdb repl unusable.
|
||||||
# Instead try to wait for pdb to be released before
|
# Instead try to wait for pdb to be released before
|
||||||
# tearing down.
|
# tearing down.
|
||||||
in_debug: tuple[str, str]|None = Lock.global_actor_in_debug
|
sub_in_debug: tuple[str, str] | None = None
|
||||||
debug_complete: trio.Event|None = Lock.no_remote_has_tty
|
|
||||||
|
|
||||||
if in_debug == current_actor().uid:
|
for _ in range(poll_steps):
|
||||||
log.debug(
|
|
||||||
msg
|
|
||||||
+
|
|
||||||
'Root already owns the TTY LOCK'
|
|
||||||
)
|
|
||||||
return True
|
|
||||||
|
|
||||||
elif in_debug:
|
if Lock.global_actor_in_debug:
|
||||||
msg += (
|
sub_in_debug = tuple(Lock.global_actor_in_debug)
|
||||||
f'Debug `Lock` in use by subactor: {in_debug}\n'
|
|
||||||
)
|
log.debug('Root polling for debug')
|
||||||
# TODO: could this make things more deterministic?
|
|
||||||
# wait to see if a sub-actor task will be
|
with trio.CancelScope(shield=True):
|
||||||
# scheduled and grab the tty lock on the next
|
await trio.sleep(poll_delay)
|
||||||
# tick?
|
|
||||||
# XXX => but it doesn't seem to work..
|
# TODO: could this make things more deterministic? wait
|
||||||
# await trio.testing.wait_all_tasks_blocked(cushion=0)
|
# to see if a sub-actor task will be scheduled and grab
|
||||||
|
# the tty lock on the next tick?
|
||||||
|
# XXX: doesn't seem to work
|
||||||
|
# await trio.testing.wait_all_tasks_blocked(cushion=0)
|
||||||
|
|
||||||
|
debug_complete = Lock.no_remote_has_tty
|
||||||
|
if (
|
||||||
|
debug_complete
|
||||||
|
and sub_in_debug is not None
|
||||||
|
and not debug_complete.is_set()
|
||||||
|
):
|
||||||
|
log.pdb(
|
||||||
|
'Root has errored but pdb is in use by '
|
||||||
|
f'child {sub_in_debug}\n'
|
||||||
|
'Waiting on tty lock to release..'
|
||||||
|
)
|
||||||
|
|
||||||
|
await debug_complete.wait()
|
||||||
|
|
||||||
|
await trio.sleep(poll_delay)
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
log.debug(
|
log.debug(
|
||||||
msg
|
'Root acquired TTY LOCK'
|
||||||
+
|
|
||||||
'Root immediately acquired debug TTY LOCK'
|
|
||||||
)
|
)
|
||||||
return False
|
|
||||||
|
|
||||||
for istep in range(poll_steps):
|
|
||||||
if (
|
|
||||||
debug_complete
|
|
||||||
and not debug_complete.is_set()
|
|
||||||
and in_debug is not None
|
|
||||||
):
|
|
||||||
log.pdb(
|
|
||||||
msg
|
|
||||||
+
|
|
||||||
'Root is waiting on tty lock to release..\n'
|
|
||||||
)
|
|
||||||
with trio.CancelScope(shield=True):
|
|
||||||
await debug_complete.wait()
|
|
||||||
log.pdb(
|
|
||||||
f'Child subactor released debug lock\n'
|
|
||||||
f'|_{in_debug}\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
# is no subactor locking debugger currently?
|
|
||||||
if (
|
|
||||||
in_debug is None
|
|
||||||
and (
|
|
||||||
debug_complete is None
|
|
||||||
or debug_complete.is_set()
|
|
||||||
)
|
|
||||||
):
|
|
||||||
log.pdb(
|
|
||||||
msg
|
|
||||||
+
|
|
||||||
'Root acquired tty lock!'
|
|
||||||
)
|
|
||||||
break
|
|
||||||
|
|
||||||
else:
|
|
||||||
# TODO: don't need this right?
|
|
||||||
# await trio.lowlevel.checkpoint()
|
|
||||||
|
|
||||||
log.debug(
|
|
||||||
'Root polling for debug:\n'
|
|
||||||
f'poll step: {istep}\n'
|
|
||||||
f'poll delya: {poll_delay}'
|
|
||||||
)
|
|
||||||
with trio.CancelScope(shield=True):
|
|
||||||
await trio.sleep(poll_delay)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# fallthrough on failure to acquire..
|
|
||||||
# else:
|
|
||||||
# raise RuntimeError(
|
|
||||||
# msg
|
|
||||||
# +
|
|
||||||
# 'Root actor failed to acquire debug lock?'
|
|
||||||
# )
|
|
||||||
return True
|
|
||||||
|
|
||||||
# else:
|
|
||||||
# # TODO: non-root call for #320?
|
|
||||||
# this_uid: tuple[str, str] = current_actor().uid
|
|
||||||
# async with acquire_debug_lock(
|
|
||||||
# subactor_uid=this_uid,
|
|
||||||
# ):
|
|
||||||
# pass
|
|
||||||
return False
|
|
||||||
|
|
||||||
# TODO: better naming and what additionals?
|
# TODO: better naming and what additionals?
|
||||||
# - [ ] optional runtime plugging?
|
# - [ ] optional runtime plugging?
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
# tractor: structured concurrent "actors".
|
|
||||||
# Copyright eternity Tyler Goodlet.
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
'''
|
|
||||||
The fundamental cross process SC abstraction: an inter-actor,
|
|
||||||
cancel-scope linked task "context".
|
|
||||||
|
|
||||||
A ``Context`` is very similar to the ``trio.Nursery.cancel_scope`` built
|
|
||||||
into each ``trio.Nursery`` except it links the lifetimes of memory space
|
|
||||||
disjoint, parallel executing tasks in separate actors.
|
|
||||||
|
|
||||||
'''
|
|
||||||
from signal import (
|
|
||||||
signal,
|
|
||||||
SIGUSR1,
|
|
||||||
)
|
|
||||||
|
|
||||||
import trio
|
|
||||||
|
|
||||||
@trio.lowlevel.disable_ki_protection
|
|
||||||
def dump_task_tree() -> None:
|
|
||||||
import stackscope
|
|
||||||
from tractor.log import get_console_log
|
|
||||||
|
|
||||||
tree_str: str = str(
|
|
||||||
stackscope.extract(
|
|
||||||
trio.lowlevel.current_root_task(),
|
|
||||||
recurse_child_tasks=True
|
|
||||||
)
|
|
||||||
)
|
|
||||||
log = get_console_log('cancel')
|
|
||||||
log.pdb(
|
|
||||||
f'Dumping `stackscope` tree:\n\n'
|
|
||||||
f'{tree_str}\n'
|
|
||||||
)
|
|
||||||
# import logging
|
|
||||||
# try:
|
|
||||||
# with open("/dev/tty", "w") as tty:
|
|
||||||
# tty.write(tree_str)
|
|
||||||
# except BaseException:
|
|
||||||
# logging.getLogger(
|
|
||||||
# "task_tree"
|
|
||||||
# ).exception("Error printing task tree")
|
|
||||||
|
|
||||||
|
|
||||||
def signal_handler(sig: int, frame: object) -> None:
|
|
||||||
import traceback
|
|
||||||
try:
|
|
||||||
trio.lowlevel.current_trio_token(
|
|
||||||
).run_sync_soon(dump_task_tree)
|
|
||||||
except RuntimeError:
|
|
||||||
# not in async context -- print a normal traceback
|
|
||||||
traceback.print_stack()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def enable_stack_on_sig(
|
|
||||||
sig: int = SIGUSR1
|
|
||||||
) -> None:
|
|
||||||
'''
|
|
||||||
Enable `stackscope` tracing on reception of a signal; by
|
|
||||||
default this is SIGUSR1.
|
|
||||||
|
|
||||||
'''
|
|
||||||
signal(
|
|
||||||
sig,
|
|
||||||
signal_handler,
|
|
||||||
)
|
|
||||||
# NOTE: not the above can be triggered from
|
|
||||||
# a (xonsh) shell using:
|
|
||||||
# kill -SIGUSR1 @$(pgrep -f '<cmd>')
|
|
|
@ -23,6 +23,10 @@ Currently popular frameworks supported are:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
from contextlib import (
|
||||||
|
# asynccontextmanager as acm,
|
||||||
|
contextmanager as cm,
|
||||||
|
)
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
|
@ -32,6 +36,9 @@ from typing_extensions import Annotated
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
|
|
||||||
|
from ._debug import open_crash_handler
|
||||||
|
|
||||||
|
|
||||||
_runtime_vars: dict[str, Any] = {}
|
_runtime_vars: dict[str, Any] = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue