-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Futures cancelled after response.write() #1430
Comments
Did you get cancelled exception from aiohttp or aiomysql? |
|
i think you should execute your query in separate task. that should solve the problem. |
What do you mean "in separate task"? Like in separate thread? |
Take a look on
https://docs.python.org/3/library/asyncio-task.html#asyncio.shield probably
is what you want
…On Tue, Nov 29, 2016, 20:59 Anderson ***@***.***> wrote:
What do you mean "in separate task"? Like in separate thread?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1430 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANoZ9GAQOJKm5Fh4fZrhPR5NQig0zKOks5rDHYWgaJpZM4K9GVd>
.
|
|
@jettify while it helps to execute the async code, it has two problems
Here is a full example:
You will see that the line with print("Next line") will not be printed. |
That's perfectly fine if a client resets a connection after receiving EOF. Current behavior is very good and clean: server's code receives a notification about client's disconnection early. It allows to stop/cancel long running tasks if needed but also allows to protect cancellation if desired. Your snippet uses Spawning new task in this particular case is also a good solution if you'll wrap it into |
Moving the shield execution above await resp.write_eof() doesn't help either. Looks like after resp.write() has been executed - all futures are canceled. Shielded futures handle cancelation, but unable to run lines after it. Regarding access log - in some situations people will want to know only the time server spoke with the client, in other - how long whole operation run. Maybe some configuration options may be added to aiohttp to address this issue? @asvetlov when you say spawning a new task, what do you mean by that? Can you give an example? |
Task spawning == No, it's not how aiohttp works. Inner futures are cancelled only on connection closing, most likely by socket shutting down by client side. Yes, shielded coroutine doesn't prevent raising Please, please, read the fucking docs carefully. |
It's not an aiohttp bug |
Long story short
After executing response.write, future that use aiomysql raise CancelledError exception. If I run the same function one line before response.write - everything works. The problem is I need to respond to client before starting to write to database, so I must do it after response.write
Steps to reproduce
Your environment
ubuntu, python3.5
The text was updated successfully, but these errors were encountered: