2020-10-04 21:31:02 +00:00
|
|
|
import tractor
|
|
|
|
import trio
|
|
|
|
|
|
|
|
|
|
|
|
async def breakpoint_forever():
|
|
|
|
"Indefinitely re-enter debugger in child actor."
|
|
|
|
while True:
|
|
|
|
await trio.sleep(0.1)
|
2024-12-09 21:08:55 +00:00
|
|
|
await tractor.pause()
|
2020-10-04 21:31:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def name_error():
|
|
|
|
"Raise a ``NameError``"
|
2021-02-24 18:39:14 +00:00
|
|
|
getattr(doggypants) # noqa
|
2020-10-04 21:31:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def spawn_error():
|
|
|
|
""""A nested nursery that triggers another ``NameError``.
|
|
|
|
"""
|
|
|
|
async with tractor.open_nursery() as n:
|
2020-12-21 14:09:55 +00:00
|
|
|
portal = await n.run_in_actor(
|
|
|
|
name_error,
|
|
|
|
name='name_error_1',
|
|
|
|
)
|
2020-10-04 21:31:02 +00:00
|
|
|
return await portal.result()
|
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
"""The main ``tractor`` routine.
|
|
|
|
|
|
|
|
The process tree should look as approximately as follows:
|
|
|
|
|
|
|
|
-python examples/debugging/multi_subactors.py
|
|
|
|
|-python -m tractor._child --uid ('name_error', 'a7caf490 ...)
|
|
|
|
|-python -m tractor._child --uid ('bp_forever', '1f787a7e ...)
|
|
|
|
`-python -m tractor._child --uid ('spawn_error', '52ee14a5 ...)
|
|
|
|
`-python -m tractor._child --uid ('name_error', '3391222c ...)
|
|
|
|
"""
|
2021-02-24 18:39:14 +00:00
|
|
|
async with tractor.open_nursery(
|
|
|
|
debug_mode=True,
|
2024-04-14 22:53:42 +00:00
|
|
|
# loglevel='runtime',
|
2021-02-24 18:39:14 +00:00
|
|
|
) as n:
|
2020-10-04 21:31:02 +00:00
|
|
|
|
2020-10-05 15:38:39 +00:00
|
|
|
# Spawn both actors, don't bother with collecting results
|
|
|
|
# (would result in a different debugger outcome due to parent's
|
|
|
|
# cancellation).
|
2020-12-21 14:09:55 +00:00
|
|
|
await n.run_in_actor(breakpoint_forever)
|
|
|
|
await n.run_in_actor(name_error)
|
|
|
|
await n.run_in_actor(spawn_error)
|
2020-10-04 21:31:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-02-24 18:39:14 +00:00
|
|
|
trio.run(main)
|