-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Float maxsize is treated as infinity in asyncio.Queue #65922
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
Comments
import asyncio
loop = asyncio.get_event_loop()
q = asyncio.Queue(maxsize=1.2, loop=loop)
q.put_nowait(1)
q.put_nowait(1)
q.put_nowait(1)
q.put_nowait(1)
q.put_nowait(1)
.... and so on It seems counter intuitive for my innocent eyes. As comparison with the traditional queue: import queue
q = queue.Queue(maxsize=1.2)
q.put(1)
q.put(1)
q.put(1) -> blocking Here is the patch to make the behaviour consistent with its sibling. |
It looks strange to use a float as maxsize. I suggest to raise a TypeError in the constructor if the type is not int, or maybe to cast maxsize parameter to an int. |
FWIW, this can also be resolved by fixing Queue.full to do "self.qsize() >= self._maxsize" instead of "self.qsize() == self._maxsize". I generally don't like implicit casts as they break duck typing. |
"It looks strange to use a float as maxsize." => It is. But the float could be coming programmatically. Float value interpreted as infinity could give a shock for some people. "maybe to cast maxsize parameter to an int." => ceiling or flooring? |
The patch looks fine to me. |
New changeset ccfc13183fea by Victor Stinner in branch '3.4': New changeset a2f115bfa513 by Victor Stinner in branch 'default': |
Thanks Vajrasky, I aplied your patch. |
Change also pushed to Tulip (changeset 3a392e5328c0). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: