Search code examples
pythonpython-2.7pycharmgeventgreenlets

using pycharm + gevent greenlet.join() no longer blocks


so after the upgrade of gevent to 1.1rc4 (from 1.0.2) while running through pycharm, I can't get greenlets to join properly... take this code for example:

from gevent import monkey, Greenlet, hub
import gevent

hub.Hub.resolver_class = ['gevent.resolver_ares.Resolver']
monkey.patch_all()

def sleepy(time):
    gevent.sleep(time)
    print "done like a good script"

if __name__ == '__main__':
    g = gevent.spawn(sleepy,10)
    g.start()
    g.join()
    print "if this is the only log line, then join didn't work"

will output:

 "if this is the only log line, then join didn't work"

from the IDE, it executes normally using the same interpreter from the CLI

I have followed the code in the cli and gui and there is a difference in behavior greenlet.join() caused by a change in behavior in hub.switch() :

 def switch(self):
    switch_out = getattr(getcurrent(), 'switch_out', None)
    if switch_out is not None:
        switch_out()
    return greenlet.switch(self)

where that last line, will return immediately, before the greenlet is executed... the pycharm debugger wont let me step into that code...

any help would be great... coroutine flow control is hard enough when it works...


Solution

  • I opened a bug at jetbrains, it was marked as a duplicate of: https://youtrack.jetbrains.com/issue/PY-14992

    I haven't looked at all of my debug issues with gevent, but this simple case was fixed with the 2016.1 release that went out 3/23/2016