Comments (4)
Hi @hollymcr,
This happens because a client is connected but it has not sent its data yet. That means the handle_echo
task is running, waiting for the data arrive. It turns out that closing the server does not cancel the pending client tasks. Actually it does not even track them:
self._loop.create_task(res)
I found a related issue on bugs.python.org: issue 28212.
from asyncio-doc.
This happens because a client is connected but it has not sent its data yet.
To be clear, whether or not any data has been sent isn't the issue, just whether the connection is still open. In the example the connection is closed immediately after data is received but that wouldn't generally be the case in real use.
That means the handle_echo task is running, waiting for the data arrive. It turns out that closing the server does not cancel the pending client tasks. Actually it does not even track them
Does this mean that the example is correct but the bug is in the library?
What is the implication of not calling loop.close()?
from asyncio-doc.
To be clear, whether or not any data has been sent isn't the issue.
You're right, but it was the simplest way to reproduce your issue.
Actually, it can happen even if the connection has been closed. Consider the following handler:
async def handle_echo(reader, writer):
writer.close()
await asyncio.sleep(100)
Does this mean that the example is correct but the bug is in the library?
That is my opinion yes. I just checked and the problem still appear in v3.7.0b3.
What is the implication of not calling loop.close()?
Consider the following handler:
async def handle_echo(reader, writer):
try:
writer.close()
await asyncio.sleep(100)
finally:
print('some cleanup')
If you comment out loop.close()
, some cleanup
is never going to run.
from asyncio-doc.
I shut down the project: #33
from asyncio-doc.
Related Issues (14)
- asyncio.rtfd.io isn't updating HOT 3
- add example explaining concurrent programming with coroutines HOT 8
- document transport read/write pause, buffer sizes, low/high water marks, etc. HOT 8
- Incorporate some content from asyncio.readthedocs.io HOT 1
- No license for example code HOT 4
- Example of both echo client server in one function HOT 2
- hello clock example HOT 3
- Update to the Read the Docs webhook HOT 1
- Shut down asyncio.readthedocs HOT 6
- HTTP Client Example is not working
- Disable the static directory HOT 1
- Update codes to Python 3.9 (stable) HOT 1
- aiohttp examples should use async context manager for session creation HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asyncio-doc.