Skip to content

Commit f8b12b1

Browse files
committed
Improve the CLI to handle asyncio.CancelledError properly
1 parent 23eca25 commit f8b12b1

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

coagent/cli/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from coagent.core import Address, RawMessage, set_stderr_logger
99
from coagent.core.exceptions import BaseError
10+
from coagent.core.messages import Cancel
1011
from coagent.runtimes import NATSRuntime, HTTPRuntime
1112

1213

@@ -68,6 +69,8 @@ async def run(
6869
else:
6970
async for chunk in runtime.channel.publish_multi(addr, msg):
7071
print_msg(chunk, oneline, filter)
72+
except asyncio.CancelledError:
73+
await runtime.channel.publish(addr, Cancel().encode(), probe=False)
7174
except BaseError as exc:
7275
print(f"Error: {exc}")
7376

0 commit comments

Comments
 (0)