Skip to content
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

Float maxsize is treated as infinity in asyncio.Queue #65922

Closed
vajrasky mannequin opened this issue Jun 11, 2014 · 8 comments
Closed

Float maxsize is treated as infinity in asyncio.Queue #65922

vajrasky mannequin opened this issue Jun 11, 2014 · 8 comments
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@vajrasky
Copy link
Mannequin

vajrasky mannequin commented Jun 11, 2014

BPO 21723
Nosy @gvanrossum, @vstinner, @1st1, @ajdavis, @vajrasky
Files
  • asyncio_queue_accept_handles_maxsize.patch
  • 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:

    assignee = None
    closed_at = <Date 2014-06-17.22:07:42.845>
    created_at = <Date 2014-06-11.15:59:54.939>
    labels = ['type-bug', 'expert-asyncio']
    title = 'Float maxsize is treated as infinity in asyncio.Queue'
    updated_at = <Date 2014-06-17.22:44:52.861>
    user = 'https://github.com/vajrasky'

    bugs.python.org fields:

    activity = <Date 2014-06-17.22:44:52.861>
    actor = 'emptysquare'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-06-17.22:07:42.845>
    closer = 'vstinner'
    components = ['asyncio']
    creation = <Date 2014-06-11.15:59:54.939>
    creator = 'vajrasky'
    dependencies = []
    files = ['35574']
    hgrepos = []
    issue_num = 21723
    keywords = ['patch']
    message_count = 8.0
    messages = ['220280', '220283', '220289', '220360', '220840', '220899', '220906', '220907']
    nosy_count = 6.0
    nosy_names = ['gvanrossum', 'vstinner', 'python-dev', 'yselivanov', 'emptysquare', 'vajrasky']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue21723'
    versions = ['Python 3.5']

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Jun 11, 2014

    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.

    @vajrasky vajrasky mannequin added topic-asyncio type-bug An unexpected behavior, bug, or error labels Jun 11, 2014
    @vstinner
    Copy link
    Member

    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.

    @1st1
    Copy link
    Member

    1st1 commented Jun 11, 2014

    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.

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Jun 12, 2014

    "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?

    @gvanrossum
    Copy link
    Member

    The patch looks fine to me.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 17, 2014

    New changeset ccfc13183fea by Victor Stinner in branch '3.4':
    Issue bpo-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 bpo-21723: asyncio.Queue: support any type of number (ex: float)
    http://hg.python.org/cpython/rev/a2f115bfa513

    @vstinner
    Copy link
    Member

    Thanks Vajrasky, I aplied your patch.

    @vstinner
    Copy link
    Member

    Change also pushed to Tulip (changeset 3a392e5328c0).

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-asyncio type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants