|
1 | 1 | from __future__ import annotations as _annotations |
2 | 2 |
|
3 | 3 | import argparse |
4 | | -import asyncio |
5 | 4 | import importlib |
6 | 5 | import os |
7 | 6 | import sys |
8 | | -from asyncio import CancelledError |
9 | 7 | from collections.abc import Sequence |
10 | 8 | from contextlib import ExitStack |
11 | 9 | from datetime import datetime, timezone |
12 | 10 | from pathlib import Path |
13 | 11 | from typing import Any, cast |
14 | 12 |
|
| 13 | +import anyio |
15 | 14 | from typing_inspection.introspection import get_literal_values |
16 | 15 |
|
17 | 16 | from . import __version__ |
@@ -209,13 +208,13 @@ def cli( # noqa: C901 |
209 | 208 |
|
210 | 209 | if prompt := cast(str, args.prompt): |
211 | 210 | try: |
212 | | - asyncio.run(ask_agent(agent, prompt, stream, console, code_theme)) |
| 211 | + anyio.run(ask_agent, agent, prompt, stream, console, code_theme) |
213 | 212 | except KeyboardInterrupt: |
214 | 213 | pass |
215 | 214 | return 0 |
216 | 215 |
|
217 | 216 | try: |
218 | | - return asyncio.run(run_chat(stream, agent, console, code_theme, prog_name)) |
| 217 | + return anyio.run(run_chat, stream, agent, console, code_theme, prog_name) |
219 | 218 | except KeyboardInterrupt: # pragma: no cover |
220 | 219 | return 0 |
221 | 220 |
|
@@ -256,7 +255,7 @@ async def run_chat( |
256 | 255 | else: |
257 | 256 | try: |
258 | 257 | messages = await ask_agent(agent, text, stream, console, code_theme, deps, messages) |
259 | | - except CancelledError: # pragma: no cover |
| 258 | + except anyio.get_cancelled_exc_class(): # pragma: no cover |
260 | 259 | console.print('[dim]Interrupted[/dim]') |
261 | 260 | except Exception as e: # pragma: no cover |
262 | 261 | cause = getattr(e, '__cause__', None) |
|
0 commit comments