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

selectors.EpollSelector.select raises exception when nothing to select. #67198

Closed
AlexeyPoryadin mannequin opened this issue Dec 8, 2014 · 13 comments
Closed

selectors.EpollSelector.select raises exception when nothing to select. #67198

AlexeyPoryadin mannequin opened this issue Dec 8, 2014 · 13 comments
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@AlexeyPoryadin
Copy link
Mannequin

AlexeyPoryadin mannequin commented Dec 8, 2014

BPO 23009
Nosy @gvanrossum, @vstinner, @1st1
Files
  • epoll_01.patch
  • epoll_02.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-12-08.17:24:07.288>
    created_at = <Date 2014-12-08.10:36:45.366>
    labels = ['type-bug', 'expert-asyncio']
    title = 'selectors.EpollSelector.select raises exception when nothing to select.'
    updated_at = <Date 2015-01-22.08:36:20.569>
    user = 'https://bugs.python.org/AlexeyPoryadin'

    bugs.python.org fields:

    activity = <Date 2015-01-22.08:36:20.569>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-12-08.17:24:07.288>
    closer = 'yselivanov'
    components = ['asyncio']
    creation = <Date 2014-12-08.10:36:45.366>
    creator = 'Alexey.Poryadin'
    dependencies = []
    files = ['37387', '37388']
    hgrepos = []
    issue_num = 23009
    keywords = ['patch']
    message_count = 13.0
    messages = ['232300', '232307', '232309', '232310', '232311', '232314', '232316', '232317', '232318', '232320', '232779', '234480', '234484']
    nosy_count = 6.0
    nosy_names = ['gvanrossum', 'vstinner', 'neologix', 'python-dev', 'yselivanov', 'Alexey.Poryadin']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue23009'
    versions = ['Python 3.4', 'Python 3.5']

    @AlexeyPoryadin
    Copy link
    Mannequin Author

    AlexeyPoryadin mannequin commented Dec 8, 2014

    When is called select, but registered no one fileobject rise exception:
    ...
    polled = self._selector.select(timeout)
    File "/usr/lib/python3.4/selectors.py", line 424, in select
    fd_event_list = self._epoll.poll(timeout, max_ev)
    ValueError: maxevents must be greater than 0, got 0

    Of course, it makes no sense to call select if there is nothing to watch. But "select.epol.poll" is not raises exception in the same case if max_ev=-1. And this simplifies the application code and is useful if need just sleep for a timeout.

    So, I suggest a small fix:

    • fd_event_list = self._epoll.poll(timeout, max_ev)
      + fd_event_list = self._epoll.poll(timeout, max_ev or -1)

    @AlexeyPoryadin AlexeyPoryadin mannequin added the type-bug An unexpected behavior, bug, or error label Dec 8, 2014
    @1st1
    Copy link
    Member

    1st1 commented Dec 8, 2014

    Patch attached. Tests pass on Linux.

    @vstinner
    Copy link
    Member

    vstinner commented Dec 8, 2014

    + s.select(timeout=0)

    I suggest to ensure that the result is an empty list.

    @1st1
    Copy link
    Member

    1st1 commented Dec 8, 2014

    I agree. Please see another one.

    @vstinner
    Copy link
    Member

    vstinner commented Dec 8, 2014

    It's a little bit surprising to call epoll_wait() without any FD subscribed, but select([], [], [], delay) is a known way to sleep 'delay' seconds, so why not using epoll in a similar way? :-)

    epoll_02.patch looks good to me. Can you please also apply the patch to the Tulip project?

    (By the way, test_selectors.py to Tulip is completly different, we may just reuse the file from CPython and drop the code from Tulip.)

    @gvanrossum
    Copy link
    Member

    Please add a comment explaining the complaint from epoll.poll() we're
    trying to avoid here.

    I presume Tulip never gets into this state because of the self-pipe.

    On Mon, Dec 8, 2014 at 8:01 AM, STINNER Victor <report@bugs.python.org>
    wrote:

    STINNER Victor added the comment:

    It's a little bit surprising to call epoll_wait() without any FD
    subscribed, but select([], [], [], delay) is a known way to sleep 'delay'
    seconds, so why not using epoll in a similar way? :-)

    epoll_02.patch looks good to me. Can you please also apply the patch to
    the Tulip project?

    (By the way, test_selectors.py to Tulip is completly different, we may
    just reuse the file from CPython and drop the code from Tulip.)

    ----------


    Python tracker <report@bugs.python.org>
    <http://bugs.python.org/issue23009\>


    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 8, 2014

    New changeset b2ee06684b6a by Yury Selivanov in branch '3.4':
    selectors: Make sure EpollSelecrtor.select() works when no FD is registered.
    https://hg.python.org/cpython/rev/b2ee06684b6a

    New changeset 202995833ef4 by Yury Selivanov in branch 'default':
    selectors: Make sure EpollSelecrtor.select() works when no FD is registered.
    https://hg.python.org/cpython/rev/202995833ef4

    @1st1
    Copy link
    Member

    1st1 commented Dec 8, 2014

    Please add a comment explaining the complaint from epoll.poll() we're
    trying to avoid here.

    Good point! Committed.

    @1st1 1st1 closed this as completed Dec 8, 2014
    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Dec 8, 2014

    Thanks for taking care of this.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 8, 2014

    New changeset 8f1be68dfcab by Yury Selivanov in branch '3.4':
    NEWS: Add news entry for issue bpo-23009.
    https://hg.python.org/cpython/rev/8f1be68dfcab

    New changeset d36711410f48 by Yury Selivanov in branch 'default':
    NEWS: Add news entry for issue bpo-23009.
    https://hg.python.org/cpython/rev/d36711410f48

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 17, 2014

    New changeset 1e985daa7be6 by Victor Stinner in branch 'default':
    Issue bpo-23009: Skip test_selectors.test_empty_select() on Windows
    https://hg.python.org/cpython/rev/1e985daa7be6

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 22, 2015

    New changeset d3a27a27e008 by Victor Stinner in branch '3.4':
    Issue bpo-23009: Skip test_selectors.test_empty_select() on Windows
    https://hg.python.org/cpython/rev/d3a27a27e008

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 22, 2015

    New changeset 4f928c70f135 by Victor Stinner in branch '3.4':
    Issue bpo-23009: Add missing "import sys" in test_selectors
    https://hg.python.org/cpython/rev/4f928c70f135

    @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