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

Begin WaitIterator iteration when __next__ is called. #1288

Merged
merged 2 commits into from Oct 16, 2018

Conversation

Projects
None yet
2 participants
@hashbrowncipher
Contributor

hashbrowncipher commented Oct 15, 2018

For scenarios where they only want to get the first greenlet which exits, a
user might write this code:

next(gevent.iwait(greenlets))

Without this commit, the above snippet will hang, because the waited-upon
objects have not been rawlink()ed. This change makes such bugs impossible.

@hashbrowncipher hashbrowncipher force-pushed the hashbrowncipher:waititerator_no_iter branch from d0e135e to 9a36ce2 Oct 15, 2018

@jamadden

Thanks!

A couple small things:

  • I would like to see a test added that that fails without this change.
  • This needs a CHANGES.rst entry
  • Please preserve the comment.
  • I think the corresponding .pxd file needs an entry for the new method 'cdef _begin(self)'

@hashbrowncipher hashbrowncipher force-pushed the hashbrowncipher:waititerator_no_iter branch from 4126f13 to 1588239 Oct 16, 2018

Begin WaitIterator iteration when __next__ is called.
For scenarios where they only want to get the first greenlet which exits, a
user might write this code:

    next(gevent.iwait(greenlets))

Without this commit, the above snippet will hang, because the waited-upon
objects have not been `rawlink()`ed. This change makes such bugs impossible.

@hashbrowncipher hashbrowncipher force-pushed the hashbrowncipher:waititerator_no_iter branch from 1588239 to 8f1916d Oct 16, 2018

@hashbrowncipher

This comment has been minimized.

Contributor

hashbrowncipher commented Oct 16, 2018

I've made the requested changes and rebased my branch to eliminate conflicts.

Changes requested in review
New test, which fails without the previous commit:

    ERROR: test_wait_noiter (__main__.TestWaiting)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/vagrant/gevent/src/greentest/greentest/leakcheck.py", line 200, in wrapper
        return _RefCountChecker(self, method)(args, kwargs)
      File "/home/vagrant/gevent/src/greentest/greentest/leakcheck.py", line 184, in __call__
        self._run_test(args, kwargs)
      File "/home/vagrant/gevent/src/greentest/greentest/leakcheck.py", line 109, in _run_test
        self.function(self.testcase, *args, **kwargs)
      File "/home/vagrant/gevent/src/greentest/greentest/errorhandler.py", line 48, in wrapper
        return method(self, *args, **kwargs)
      File "/home/vagrant/gevent/src/greentest/greentest/errorhandler.py", line 35, in wrapper
        return method(self, *args, **kwargs)
      File "/home/vagrant/gevent/src/greentest/greentest/testcase.py", line 63, in wrapper
        return method(self, *args, **kwargs)
      File "src/greentest/test__wait.py", line 12, in test_wait_noiter
        ready = next(gevent.iwait((sem1, sem2)))
      File "src/gevent/_hub_primitives.py", line 149, in gevent.__hub_primitives._WaitIterator.__next__
        raise
      File "src/gevent/_hub_primitives.py", line 140, in gevent.__hub_primitives._WaitIterator.__next__
        item = self._waiter.get()
      File "src/gevent/_waiter.py", line 192, in gevent.__waiter.MultipleWaiter.get
        Waiter.get(self)
      File "src/gevent/_waiter.py", line 151, in gevent.__waiter.Waiter.get
        return self.hub.switch()
      File "src/gevent/_greenlet_primitives.py", line 59, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
        def switch(self):
      File "src/gevent/_greenlet_primitives.py", line 59, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
        def switch(self):
      File "src/gevent/_greenlet_primitives.py", line 63, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
        return _greenlet_switch(self) # pylint:disable=undefined-variable
      File "src/gevent/__greenlet_primitives.pxd", line 35, in gevent.__greenlet_primitives._greenlet_switch
        return PyGreenlet_Switch(self, NULL, NULL)
    LoopExit: This operation would block forever
        Hub: <QuietHub '' at 0x7fc8fce60520 epoll default pending=0 ref=0 fileno=3 thread_ident=0x7fc8fffbe700>
        Handles:
    []

@hashbrowncipher hashbrowncipher force-pushed the hashbrowncipher:waititerator_no_iter branch from 8f1916d to 105259e Oct 16, 2018

@jamadden jamadden merged commit 105259e into gevent:master Oct 16, 2018

0 of 2 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@jamadden

This comment has been minimized.

Member

jamadden commented Oct 16, 2018

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment