Comments (5)
Yes, we should probably have this - I won't be able to add it myself for a while though as I've got bugs to fix elsewhere. Feel free to submit a PR if you want.
from asgiref.
Ok, fine. What about the following? (I'm not sure about the sleep times yet. And I'd actually prefer to implement queue_empty
simpler...)
async def queue_empty(self, timeout=0.1):
if not self.output_queue.empty():
return False
if timeout <= 0.01:
await asyncio.sleep(timeout)
return self.output_queue.empty()
await asyncio.sleep(0.01)
if not self.output_queue.empty():
return False
await asyncio.sleep(timeout - 0.01)
return self.output_queue.empty()
async def queue_count(self, wait=0.1):
await asyncio.sleep(wait)
return self.output_queue.qsize()
from asgiref.
I'd just have one top-level function called communicator.receive_nothing
that raises an (assertion?) error if it does receive something, that just wraps receive_from and catches the TimeoutError
.
from asgiref.
I also thought about doing it that way. But as far as I understand the communicator is closed after this exception which is not what I want in some use cases...
from asgiref.
Ah yes, the timeout will cancel it. I still think calling it receive_nothing
makes sense though, and implement inside that as you see fit (using queue empty detection is fine)
from asgiref.
Related Issues (20)
- Relax typing of lifespan state from Dict[str, Any] to Dict[Any, Any] HOT 4
- Using `contextvars` in `local.py`? HOT 2
- Proposal: introduce `http.response.pathsend` extension HOT 2
- Behavior on `WebSocket.Send` on disconnection HOT 5
- RFE: please start making github releases HOT 3
- asgiref's WsgiToAsgi wrapper does not handle "client": None per spec
- Parameters to Generic[...] must all be type variables HOT 2
- ApplicationCommunicator cancels the application future unnecessarily? HOT 3
- Communicating client disconnects without receiving the request body HOT 11
- Documentation suggestion - Cookie header handling for HTTP/2 HOT 2
- Is the server in charge of making sure the `Content-Length` matches the body? HOT 1
- Re-evaluate "http.response.zerocopysend" HOT 8
- About `scope[path]` and `scope[root_path]` HOT 11
- Add Type Annotations to `asgiref` Module HOT 1
- Add Type Annotations to `asgiref` Module Functions HOT 2
- Parameters to Generic[...] must all be type variables when use with sys.setprofile HOT 3
- Can asig http extensions be used in WebSocket Denial Response? HOT 2
- Using asyncio.shield hangs/deadlocks when used with sync middleware. HOT 10
- What am I allowed to do with the send/receive callables? HOT 1
- Wording: should “extra coroutines” actually be “extra tasks”? 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 asgiref.