Skip to content
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

Proper breakpoint() hooking #351

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
24a0623
Just call `trio.Process.aclose()` directly for now?
goodboy Apr 2, 2023
f667d16
Copy the now deprecated `trio.Process.aclose()`
goodboy May 14, 2023
d1e9b32
Switch to `pdbp` since noone is maintaining `pdbpp`
goodboy Apr 15, 2023
125b96b
Change over debugger tests to use `PROMPT` var..
goodboy Apr 15, 2023
104edc0
Use multiline import for debug mod
goodboy Apr 15, 2023
43ecaf0
First try: switch debug machinery over to `pdbp` B)
goodboy Apr 15, 2023
45b61ff
Hide actor nursery exit frame
goodboy Apr 15, 2023
18bc9f9
Yeahh.. maybe sticky off by default is a little better for us XD
goodboy Apr 17, 2023
47ab1dd
`pdbp`: turn off line truncating by default, fixes terminal resizing …
goodboy Apr 19, 2023
6c78bd7
TOSQUASH 4759e30: turn it ON i guess? XD
goodboy Apr 20, 2023
79aeaee
pdbp: adding typing to config settings vars
goodboy May 8, 2023
38330db
Enable `Context` backpressure by default; avoid startup race-crashes?
goodboy Mar 7, 2023
2d3ccd5
More single doc-strs in discovery mod
goodboy Mar 7, 2023
e418513
Tweak context doc str
goodboy Apr 2, 2023
f9d72f2
Add some log-level method doc-strings
goodboy Apr 4, 2023
c3a6163
Change a bunch of log levels to cancel, including any `ContextCancell…
goodboy Apr 7, 2023
6457bac
Assign `RemoteActorError` boxed error type for context cancelleds
goodboy Apr 7, 2023
9923926
Log waiter task cancelling msg as cancel-level
goodboy Apr 7, 2023
db5cc9f
Add new set of context cancellation tests
goodboy Apr 12, 2023
af600cb
Add new remote error introspection attrs
goodboy Apr 12, 2023
a26d1de
Augment test cases for callee-returns-result early
goodboy Apr 13, 2023
46a7d42
Move `NoRuntime` import inside `current_actor()` to avoid cycle
goodboy Apr 13, 2023
bed65b1
Only tuplize `.canceller` if non-`None`
goodboy Apr 13, 2023
a6f121e
Remote `Context` cancellation semantics rework B)
goodboy Apr 13, 2023
6bb9b08
Drop brackpressure usage from fan out tests
goodboy Apr 13, 2023
dbd007c
Flip allocate log msgs to debug
goodboy Apr 13, 2023
19357fc
Fix cluster test to use `allow_overruns`
goodboy Apr 13, 2023
f60ea22
Adjust aio test for silent cancellation by parent
goodboy Apr 13, 2023
b04835a
Seriously cover all overrun cases
goodboy Apr 13, 2023
1338cb3
Set `Context._scope_nursery` on callee side too
goodboy Apr 14, 2023
5d65a15
Ignore drainer-task nursery RTE during context exit
goodboy Apr 14, 2023
95c12c3
Drop caller cancels overrun test; covered in new tests
goodboy Apr 14, 2023
669360a
Move move context code into new `._context` mod
goodboy Apr 14, 2023
a8eb962
Tweak doc string
goodboy Apr 14, 2023
0c39371
Restore `breakpoint()` hook after runtime exits
goodboy Mar 7, 2023
c95e440
Add (first-draft) infected-`asyncio` actor task uses debugger example
goodboy Mar 7, 2023
bdaad74
Some more 3.10+ optional type sigs
goodboy Mar 7, 2023
3a62cf6
Add a debug-mode-breakpoint-causes-hang case!
goodboy Mar 27, 2023
1c1f9e0
Oof, fix remaining `Actor.cancel()` in `Actor._from_parent()`
goodboy Apr 20, 2023
021bb38
Expose `allow_overruns` to `Portal.open_context()`
goodboy May 12, 2023
9ca5fdf
Add news file
goodboy May 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions examples/debugging/asyncio_bp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import asyncio

import trio
import tractor
from tractor import to_asyncio


async def aio_sleep_forever():
await asyncio.sleep(float('inf'))


async def bp_then_error(
to_trio: trio.MemorySendChannel,
from_trio: asyncio.Queue,

raise_after_bp: bool = True,

) -> None:

# sync with ``trio``-side (caller) task
to_trio.send_nowait('start')

# NOTE: what happens here inside the hook needs some refinement..
# => seems like it's still `._debug._set_trace()` but
# we set `Lock.local_task_in_debug = 'sync'`, we probably want
# some further, at least, meta-data about the task/actoq in debug
# in terms of making it clear it's asyncio mucking about.
breakpoint()

# short checkpoint / delay
await asyncio.sleep(0.5)

if raise_after_bp:
raise ValueError('blah')

# TODO: test case with this so that it gets cancelled?
else:
# XXX NOTE: this is required in order to get the SIGINT-ignored
# hang case documented in the module script section!
await aio_sleep_forever()


@tractor.context
async def trio_ctx(
ctx: tractor.Context,
bp_before_started: bool = False,
):

# this will block until the ``asyncio`` task sends a "first"
# message, see first line in above func.
async with (

to_asyncio.open_channel_from(
bp_then_error,
raise_after_bp=not bp_before_started,
) as (first, chan),

trio.open_nursery() as n,
):

assert first == 'start'

if bp_before_started:
await tractor.breakpoint()

await ctx.started(first)

n.start_soon(
to_asyncio.run_task,
aio_sleep_forever,
)
await trio.sleep_forever()


async def main(
bps_all_over: bool = False,

) -> None:

async with tractor.open_nursery() as n:

p = await n.start_actor(
'aio_daemon',
enable_modules=[__name__],
infect_asyncio=True,
debug_mode=True,
loglevel='cancel',
)

async with p.open_context(
trio_ctx,
bp_before_started=bps_all_over,
) as (ctx, first):

assert first == 'start'

if bps_all_over:
await tractor.breakpoint()

# await trio.sleep_forever()
await ctx.cancel()
assert 0

# TODO: case where we cancel from trio-side while asyncio task
# has debugger lock?
# await p.cancel_actor()


if __name__ == '__main__':

# works fine B)
trio.run(main)

# will hang and ignores SIGINT !!
# NOTE: you'll need to send a SIGQUIT (via ctl-\) to kill it
# manually..
# trio.run(main, True)
24 changes: 24 additions & 0 deletions examples/debugging/restore_builtin_breakpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
import sys

import trio
import tractor


async def main() -> None:
async with tractor.open_nursery(debug_mode=True) as an:

assert os.environ['PYTHONBREAKPOINT'] == 'tractor._debug._set_trace'

# TODO: an assert that verifies the hook has indeed been, hooked
# XD
assert sys.breakpointhook is not tractor._debug._set_trace

breakpoint()

# TODO: an assert that verifies the hook is unhooked..
assert sys.breakpointhook
breakpoint()

if __name__ == '__main__':
trio.run(main)
7 changes: 7 additions & 0 deletions nooz/356.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Drop `trio.Process.aclose()` usage, copy into our spawning code.

The details are laid out in https://github.com/goodboy/tractor/issues/330.
`trio` changed is process running quite some time ago, this just copies
out the small bit we needed (from the old `.aclose()`) for hard kills
where a soft runtime cancel request fails and our "zombie killer"
implementation kicks in.
13 changes: 5 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
setup(
name="tractor",
version='0.1.0a6dev0', # alpha zone
description='structured concurrrent "actors"',
description='structured concurrrent `trio`-"actors"',
long_description=readme,
license='AGPLv3',
author='Tyler Goodlet',
maintainer='Tyler Goodlet',
maintainer_email='jgbt@protonmail.com',
maintainer_email='goodboy_foss@protonmail.com',
url='https://github.com/goodboy/tractor',
platforms=['linux', 'windows'],
packages=[
Expand All @@ -52,16 +52,14 @@
# tooling
'tricycle',
'trio_typing',

# tooling
'colorlog',
'wrapt',

# serialization
# IPC serialization
'msgspec',

# debug mode REPL
'pdbpp',
'pdbp',

# pip ref docs on these specs:
# https://pip.pypa.io/en/stable/reference/requirement-specifiers/#examples
Expand All @@ -73,10 +71,9 @@
# https://github.com/pdbpp/fancycompleter/issues/37
'pyreadline3 ; platform_system == "Windows"',


],
tests_require=['pytest'],
python_requires=">=3.9",
python_requires=">=3.10",
keywords=[
'trio',
'async',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def worker(
await ctx.started()

async with ctx.open_stream(
backpressure=True,
allow_overruns=True,
) as stream:

# TODO: this with the below assert causes a hang bug?
Expand Down
Loading