-
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 #220 from goodboy/ctx_debugger
Ctx debugger
- Loading branch information
Showing
9 changed files
with
481 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
''' | ||
Fast fail test with a context. | ||
Ensure the partially initialized sub-actor process | ||
doesn't cause a hang on error/cancel of the parent | ||
nursery. | ||
''' | ||
import trio | ||
import tractor | ||
|
||
|
||
@tractor.context | ||
async def sleep( | ||
ctx: tractor.Context, | ||
): | ||
await trio.sleep(0.5) | ||
await ctx.started() | ||
await trio.sleep_forever() | ||
|
||
|
||
async def open_ctx( | ||
n: tractor._trionics.ActorNursery | ||
): | ||
|
||
# spawn both actors | ||
portal = await n.start_actor( | ||
name='sleeper', | ||
enable_modules=[__name__], | ||
) | ||
|
||
async with portal.open_context( | ||
sleep, | ||
) as (ctx, first): | ||
assert first is None | ||
|
||
|
||
async def main(): | ||
|
||
async with tractor.open_nursery( | ||
debug_mode=True, | ||
loglevel='runtime', | ||
) as an: | ||
|
||
async with trio.open_nursery() as n: | ||
n.start_soon(open_ctx, an) | ||
|
||
await trio.sleep(0.2) | ||
await trio.sleep(0.1) | ||
assert 0 | ||
|
||
|
||
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,31 @@ | ||
|
||
import trio | ||
import tractor | ||
|
||
|
||
async def key_error(): | ||
"Raise a ``NameError``" | ||
return {}['doggy'] | ||
|
||
|
||
async def main(): | ||
"""Root dies | ||
""" | ||
async with tractor.open_nursery( | ||
debug_mode=True, | ||
loglevel='debug' | ||
) as n: | ||
|
||
# spawn both actors | ||
portal = await n.run_in_actor(key_error) | ||
|
||
# XXX: originally a bug caused by this is where root would enter | ||
# the debugger and clobber the tty used by the repl even though | ||
# child should have it locked. | ||
with trio.fail_after(1): | ||
await trio.Event().wait() | ||
|
||
|
||
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
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.