tractor/examples/debugging/subactor_bp_in_ctx.py

51 lines
913 B
Python
Raw Permalink Normal View History

2022-01-27 04:38:33 +00:00
import tractor
import trio
async def gen():
yield 'yo'
await tractor.breakpoint()
yield 'yo'
2022-02-16 18:59:23 +00:00
await tractor.breakpoint()
2022-01-27 04:38:33 +00:00
@tractor.context
async def just_bp(
ctx: tractor.Context,
) -> None:
2022-02-16 18:59:23 +00:00
await ctx.started()
await tractor.breakpoint()
2022-02-09 15:05:21 +00:00
# TODO: bps and errors in this call..
2022-02-16 18:59:23 +00:00
async for val in gen():
print(val)
# await trio.sleep(0.5)
2022-02-16 18:59:23 +00:00
# prematurely destroy the connection
await ctx.chan.aclose()
2022-02-09 15:05:21 +00:00
# THIS CAUSES AN UNRECOVERABLE HANG
# without latest ``pdbpp``:
assert 0
2022-01-27 04:38:33 +00:00
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)