geertj / gruvi

Async IO for Python, Simplified

Home Page:http://gruvi.readthedocs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hang in example

faassen opened this issue · comments

I may not be doing it right, but I tried this example:

from gruvi import Fiber, get_hub


def say_hello():
    print('Hello, there!')

fiber = Fiber(say_hello)
fiber.start()

print('Starting fiber')
get_hub().switch()
print('Back in root fiber')

From the docs it says it should print the following:

Starting fiber
Hello, there!
Back in root fiber

instead it prints:

Starting fiber
Hello, there!

and then hangs indefinitely. This is in Python 2.7.10 on Fedora release 22, using a virtualenv.

Hello @faassen

Thanks for the report! Not sure if you're still interested in this given that it's a long time ago. But in recent weeks I finally got some free time again to work on Gruvi.

The example from the documentation is incorrect, and I have fixed it in 44edf39. The code was switching to the Hub, without arranging for a switchback. This caused the hub to run the loop indefinitely. The only way out was either CTRL-C, or a cross-thread interrupt.

The fixed example does a simple sleep(0) which switches to the hub but also schedules an immediate switchback to the originating fiber.