-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from goodboy/signint_saviour
Ignore SIGINT when in a debugger REPL
- Loading branch information
Showing
21 changed files
with
1,279 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import trio | ||
import tractor | ||
|
||
|
||
@tractor.context | ||
async def just_sleep( | ||
|
||
ctx: tractor.Context, | ||
**kwargs, | ||
|
||
) -> None: | ||
''' | ||
Start and sleep. | ||
''' | ||
await ctx.started() | ||
await trio.sleep_forever() | ||
|
||
|
||
async def main() -> None: | ||
|
||
async with tractor.open_nursery( | ||
debug_mode=True, | ||
) as n: | ||
portal = await n.start_actor( | ||
'ctx_child', | ||
|
||
# XXX: we don't enable the current module in order | ||
# to trigger `ModuleNotFound`. | ||
enable_modules=[], | ||
) | ||
|
||
async with portal.open_context( | ||
just_sleep, # taken from pytest parameterization | ||
) as (ctx, sent): | ||
raise KeyboardInterrupt | ||
|
||
|
||
if __name__ == '__main__': | ||
trio.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import tractor | ||
import trio | ||
|
||
|
||
async def gen(): | ||
yield 'yo' | ||
await tractor.breakpoint() | ||
yield 'yo' | ||
await tractor.breakpoint() | ||
|
||
|
||
@tractor.context | ||
async def just_bp( | ||
ctx: tractor.Context, | ||
) -> None: | ||
|
||
await ctx.started() | ||
await tractor.breakpoint() | ||
|
||
# TODO: bps and errors in this call.. | ||
async for val in gen(): | ||
print(val) | ||
|
||
# await trio.sleep(0.5) | ||
|
||
# prematurely destroy the connection | ||
await ctx.chan.aclose() | ||
|
||
# THIS CAUSES AN UNRECOVERABLE HANG | ||
# without latest ``pdbpp``: | ||
assert 0 | ||
|
||
|
||
|
||
async def main(): | ||
async with tractor.open_nursery( | ||
debug_mode=True, | ||
) as n: | ||
p = await n.start_actor( | ||
'bp_boi', | ||
enable_modules=[__name__], | ||
) | ||
async with p.open_context( | ||
just_bp, | ||
) as (ctx, first): | ||
await trio.sleep_forever() | ||
|
||
|
||
if __name__ == '__main__': | ||
trio.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import trio | ||
import click | ||
import tractor | ||
import pydantic | ||
# from multiprocessing import shared_memory | ||
|
||
|
||
@tractor.context | ||
async def just_sleep( | ||
|
||
ctx: tractor.Context, | ||
**kwargs, | ||
|
||
) -> None: | ||
''' | ||
Test a small ping-pong 2-way streaming server. | ||
''' | ||
await ctx.started() | ||
await trio.sleep_forever() | ||
|
||
|
||
async def main() -> None: | ||
|
||
proc = await trio.open_process( ( | ||
'python', | ||
'-c', | ||
'import trio; trio.run(trio.sleep_forever)', | ||
)) | ||
await proc.wait() | ||
# await trio.sleep_forever() | ||
# async with tractor.open_nursery() as n: | ||
|
||
# portal = await n.start_actor( | ||
# 'rpc_server', | ||
# enable_modules=[__name__], | ||
# ) | ||
|
||
# async with portal.open_context( | ||
# just_sleep, # taken from pytest parameterization | ||
# ) as (ctx, sent): | ||
# await trio.sleep_forever() | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
import time | ||
# time.sleep(999) | ||
trio.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Add SIGINT protection to our `pdbpp` based debugger subystem such that | ||
for (single-depth) actor trees in debug mode we ignore interrupts in any | ||
actor currently holding the TTY lock thus avoiding clobbering IPC | ||
connections and/or task and process state when working in the REPL. | ||
|
||
As a big note currently so called "nested" actor trees (trees with | ||
actors having more then one parent/ancestor) are not fully supported | ||
since we don't yet have a mechanism to relay the debug mode knowledge | ||
"up" the actor tree (for eg. when handling a crash in a leaf actor). | ||
As such currently there is a set of tests and known scenarios which will | ||
result in process cloberring by the zombie repaing machinery and these | ||
have been documented in https://github.com/goodboy/tractor/issues/320. | ||
|
||
The implementation details include: | ||
|
||
- utilizing a custom SIGINT handler which we apply whenever an actor's | ||
runtime enters the debug machinery, which we also make sure the | ||
stdlib's `pdb` configuration doesn't override (which it does by | ||
default without special instance config). | ||
- litter the runtime with `maybe_wait_for_debugger()` mostly in spots | ||
where the root actor should block before doing embedded nursery | ||
teardown ops which both cancel potential-children-in-deubg as well | ||
as eventually trigger zombie reaping machinery. | ||
- hardening of the TTY locking semantics/API both in terms of IPC | ||
terminations and cancellation and lock release determinism from | ||
sync debugger instance methods. | ||
- factoring of locking infrastructure into a new `._debug.Lock` global | ||
which encapsulates all details of the ``trio`` sync primitives and | ||
task/actor uid management and tracking. | ||
|
||
We also add `ctrl-c` cases throughout the test suite though these are | ||
disabled for py3.9 (`pdbpp` UX differences that don't seem worth | ||
compensating for, especially since this will be our last 3.9 supported | ||
release) and there are a slew of marked cases that aren't expected to | ||
work in CI more generally (as mentioned in the "nested" tree note | ||
above) despite seemingly working when run manually on linux. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pytest | ||
pytest-trio | ||
pytest-timeout | ||
pdbpp | ||
mypy<0.920 | ||
trio_typing<0.7.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.