Created
August 29, 2013 05:19
-
-
Save rbranson/6374514 to your computer and use it in GitHub Desktop.
Illustrates how to launch & yield to gevent greenlets from a non-gevent context.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gevent | |
from gevent import httplib | |
def fetcher(): | |
print "fetcher: Fetching..." | |
conn = httplib.HTTPConnection("www.google.com") | |
conn.request("GET", "/") | |
res = conn.getresponse() | |
output = res.read() | |
print "fether: Received %s bytes" % len(output) | |
print "main: Spawning..." | |
g = gevent.spawn(fetcher) | |
print "main: Spawned." | |
gevent.sleep(0) | |
print "main: Sleeped." | |
gevent.joinall([g]) | |
print "main: Joined." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment