2020-10-16 03:15:20 +00:00
|
|
|
import tractor
|
|
|
|
import trio
|
|
|
|
|
|
|
|
|
|
|
|
async def breakpoint_forever():
|
|
|
|
"Indefinitely re-enter debugger in child actor."
|
2024-05-28 13:22:59 +00:00
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
yield 'yo'
|
2024-12-09 21:08:55 +00:00
|
|
|
await tractor.pause()
|
2024-05-28 13:22:59 +00:00
|
|
|
except BaseException:
|
|
|
|
tractor.log.get_console_log().exception(
|
|
|
|
'Cancelled while trying to enter pause point!'
|
|
|
|
)
|
|
|
|
raise
|
2020-10-16 03:15:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def name_error():
|
|
|
|
"Raise a ``NameError``"
|
2021-02-24 18:39:14 +00:00
|
|
|
getattr(doggypants) # noqa
|
2020-10-16 03:15:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
"""Test breakpoint in a streaming actor.
|
|
|
|
"""
|
2021-02-23 11:48:15 +00:00
|
|
|
async with tractor.open_nursery(
|
|
|
|
debug_mode=True,
|
2024-07-12 19:57:41 +00:00
|
|
|
# loglevel='cancel',
|
|
|
|
# loglevel='devx',
|
2021-02-23 11:48:15 +00:00
|
|
|
) as n:
|
2020-10-16 03:15:20 +00:00
|
|
|
|
2021-02-23 11:48:15 +00:00
|
|
|
p0 = await n.start_actor('bp_forever', enable_modules=[__name__])
|
|
|
|
p1 = await n.start_actor('name_error', enable_modules=[__name__])
|
2020-10-16 03:15:20 +00:00
|
|
|
|
|
|
|
# retreive results
|
2021-04-28 15:54:56 +00:00
|
|
|
async with p0.open_stream_from(breakpoint_forever) as stream:
|
2022-10-14 19:40:48 +00:00
|
|
|
|
|
|
|
# triggers the first name error
|
|
|
|
try:
|
|
|
|
await p1.run(name_error)
|
|
|
|
except tractor.RemoteActorError as rae:
|
2024-03-19 22:08:54 +00:00
|
|
|
assert rae.boxed_type is NameError
|
2022-10-14 19:40:48 +00:00
|
|
|
|
|
|
|
async for i in stream:
|
|
|
|
|
|
|
|
# a second time try the failing subactor and this tie
|
|
|
|
# let error propagate up to the parent/nursery.
|
|
|
|
await p1.run(name_error)
|
2020-10-16 03:15:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-02-23 11:48:15 +00:00
|
|
|
trio.run(main)
|