aio-libs / aio-libs/aiohttp-sse
Having to handle CancelledError instead of it working automatically
- Lingua principale
- Python
- Stelle
- 238
- Fork
- 37
- Merge medio
- 2m
- PR unite (30g)
- 1
Descrizione
I am having to do
```py
try:
async with sse_response(request) as response:
async for event in self.execute_workflow(
layers, caller_user, resolved_workflow, payload
):
await response.send(json.dumps(event.to_json()))
except asyncio.CancelledError:
# aiohttp_sse is not handling the finishing of the response properly
# and it is raising an internal CancelledError used for stopping the
# response. We have to catch it and ignore it.
logger.debug(
"Ignoring cancelled error in streaming workflow request", exc_info=True
)
```
And if we look at the exc info it is happening inside the lib:
```
Ignoring cancelled error in streaming workflow request
Traceback (most recent call last):
File "/opt/isolate_controller/projects/isolate_controller/isolate_controller/gateway/_gateway.py", line 1071, in streaming_workflow_request
async with sse_response(request) as response:
File "/usr/local/lib/python3.11/site-packages/aiohttp_sse/helpers.py", line 61, in __aexit__
return await self._obj.__aexit__(exc_type, exc, tb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aiohttp_sse/__init__.py", line 221, in __aexit__
await self.wait()
File "/usr/local/lib/python3.11/site-packages/aiohttp_sse/__init__.py", line 147, in wait
await self._ping_task
File "/usr/local/lib/python3.11/site-packages/aiohttp_sse/__init__.py", line 203, in _ping
await asyncio.sleep(self._ping_interval)
File "/usr/local/lib/python3.11/asyncio/tasks.py", line 649, in sleep
return await future
^^^^^^^^^^^^
asyncio.exceptions.CancelledError
```
https://github.com/aio-libs/aiohttp-sse/blob/e2f46bf7890f82746b1cd0f1fc8e9edd5e429f62/aiohttp_sse/__init__.py#L138-L162
I do not see any other source of CancelledError being riased in my code, so I am thinking this is somehow maybe getting the wrong reference in `asyncio.current_task()`?
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.