-
-
Save piotr-dobrogost/1584694 to your computer and use it in GitHub Desktop.
learning gevent...
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
from gevent import monkey | |
monkey.patch_all() | |
import gevent | |
import requests | |
def http_req(x, url): | |
r = requests.post(url) | |
print "Request ", x, r | |
def http_req2(greenlet): | |
r = requests.post('http://python-guide.org') | |
print "Request ", r | |
if __name__ == '__main__': | |
greens = [gevent.spawn(http_req, x, 'http://httpbin.org') for x in range(4)] | |
print "waiting end of greenlets ..." | |
gevent.joinall(greens) | |
for green in greens: | |
green.link(http_req2) | |
gevent.joinall(greens) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try replacing gevent.joinall() with gevent.run()