StreamingResponse with async generator get stuck indefinitely · encode/starlette...
source link: https://github.com/encode/starlette/discussions/1776
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
StreamingResponse with async generator get stuck indefinitely · encode/starlette · Discussion #1776 · GitHub
The starting point for issues should usually be a discussion... https://github.com/encode/starlette/discussions Possible bugs may be raised as a "Potential Issue" discussion, feature requests may be raised as an "Ideas" discussion. We can then determine if the discussion needs to be escalated into an "Issue" or not. This will help us ensure that the "Issues" list properly reflects ongoing or needed work on the project.
CASE 1: When
CASE 2: When
When CASE 1, even `Keyboard Interrupts are ignored. I had to kill Python process forcefully. |
If you add an await asyncio.sleep(0)
, does it solve the problem?
async def async_streamer():
try:
while True:
yield b"--boundary\r\nContent-Type: text/plain\r\nContent-Length: 1\r\n\r\n1\r\n"
await asyncio.sleep(0) # <--
except asyncio.CancelledError:
print("caught cancelled error")
raise GeneratorExit
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK