From 266073cb69a22bb765a2f0340e72b4b761aabab4 Mon Sep 17 00:00:00 2001 From: goodboy Date: Tue, 25 Aug 2026 20:03:18 -0400 Subject: [PATCH] Reap the `@pub` example daemon on stream exit Wrap the documented publisher stream in `try/finally` and explicitly cancel its `start_actor()` daemon. Closing `open_stream_from()` owns only the remote stream task, so actor-nursery exit otherwise waits on the still-running actor indefinitely. Review: PR #484 (OpenCode) https://github.com/goodboy/tractor/pull/484#pullrequestreview-5025383596 (this patch was generated in some part by `opencode` using `gpt-5.6-sol` (`openai`)) --- tractor/experimental/_pubsub.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tractor/experimental/_pubsub.py b/tractor/experimental/_pubsub.py index e23fdc71..55233ae6 100644 --- a/tractor/experimental/_pubsub.py +++ b/tractor/experimental/_pubsub.py @@ -224,13 +224,16 @@ def pub( 'publisher', # actor name enable_modules=[__name__], ) - async with portal.open_stream_from( - pub_service, # func to execute in it - topics=('clicks', 'users'), - task_name='source1', - ) as stream: - async for value in stream: - print(f"Subscriber received {value}") + try: + async with portal.open_stream_from( + pub_service, # func to execute in it + topics=('clicks', 'users'), + task_name='source1', + ) as stream: + async for value in stream: + print(f"Subscriber received {value}") + finally: + await portal.cancel_actor() Here, you don't need to provide the ``ctx`` argument since the