classification
Title: Float maxsize is treated as infinity in asyncio.Queue
Type: behavior Stage:
Components: asyncio Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: emptysquare, gvanrossum, haypo, python-dev, vajrasky, yselivanov
Priority: normal Keywords: patch

Created on 2014-06-11 15:59 by vajrasky, last changed 2014-06-17 22:44 by emptysquare. This issue is now closed.

Files
File name Uploaded Description Edit
asyncio_queue_accept_handles_maxsize.patch vajrasky, 2014-06-11 15:59 review
Messages (8)
msg220280 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2014-06-11 15:59
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.
msg220283 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2014-06-11 16:12
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.
msg220289 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-06-11 17:22
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.
msg220360 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2014-06-12 16:08
"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?
msg220840 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2014-06-17 15:51
The patch looks fine to me.
msg220899 - (view) Author: Roundup Robot (python-dev) Date: 2014-06-17 21:40
New changeset ccfc13183fea by Victor Stinner in branch '3.4':
Issue #21723: asyncio.Queue: support any type of number (ex: float) for the
http://hg.python.org/cpython/rev/ccfc13183fea

New changeset a2f115bfa513 by Victor Stinner in branch 'default':
(Merge 3.4) Issue #21723: asyncio.Queue: support any type of number (ex: float)
http://hg.python.org/cpython/rev/a2f115bfa513
msg220906 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2014-06-17 22:07
Thanks Vajrasky, I aplied your patch.
msg220907 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2014-06-17 22:07
Change also pushed to Tulip (changeset 3a392e5328c0).
History
Date User Action Args
2014-06-17 22:44:52emptysquaresetnosy: + emptysquare
2014-06-17 22:07:47hayposetmessages: + msg220907
2014-06-17 22:07:42hayposetstatus: open -> closed
resolution: fixed
messages: + msg220906
2014-06-17 21:40:59python-devsetnosy: + python-dev
messages: + msg220899
2014-06-17 15:51:29gvanrossumsetmessages: + msg220840
2014-06-12 16:08:07vajraskysetmessages: + msg220360
2014-06-11 17:22:16yselivanovsetmessages: + msg220289
2014-06-11 16:12:32hayposetmessages: + msg220283
2014-06-11 15:59:54vajraskycreate