Python – Flask-SocketIO send message from thread: not always working

I managed to resolve the issue by monkeypatching several Python functions which causes Python to use the eventlet functions instead of the native ones. This way background threads work fine with eventlet. https://github.com/miguelgrinberg/Flask-SocketIO/blob/e024b7ec9db4837196d8a46ad1cb82bc1e15f1f3/example/app.py#L30-L31

aiogevent event loop “fails” to track greenlets

Taking a guess at this, but I think you’re using the event loop wrong for asyncio. I don’t know enough about gevent to understand what type of object it’s creating to know if this will work. The documentation would indicate that the order in which stop() and run_forever() are called is relevant to the operational … Read more

Eventlet vs Greenlet vs gevent?

You definitely don’t want greenlet for this purpose, because it’s a low level library on top of which you can create light thread libraries (like Eventlet and Gevent). Eventlet, Gevent and more similar libraries provide excellent toolset for IO-bound tasks (waiting for read/write on file, network). Likely, most of your GUI code will wait for … Read more

Eventlet or gevent or Stackless + Twisted, Pylons, Django and SQL Alchemy

You might want to check out: Comparing gevent to eventlet Reports from users who moved from twisted or eventlet to gevent Eventlet and gevent are not really comparable to Stackless, because Stackless ships with a standard library that is not aware of tasklets. There are implementations of socket for Stackless but there isn’t anything as … Read more

Python requests with multithreading

Install the grequests module which works with gevent (requests is not designed for async): pip install grequests Then change the code to something like this: import grequests class Test: def __init__(self): self.urls = [ ‘http://www.example.com’, ‘http://www.google.com’, ‘http://www.yahoo.com’, ‘http://www.stackoverflow.com/’, ‘http://www.reddit.com/’ ] def exception(self, request, exception): print “Problem: {}: {}”.format(request.url, exception) def async(self): results = grequests.map((grequests.get(u) for … Read more

In what way is grequests asynchronous?

.map() is meant to run retrieval of several URLs in parallel, and will indeed wait for these tasks to complete (gevent.joinall(jobs)) is called). Use .send() instead to spawn jobs, using a Pool instance: req = grequests.get(‘http://www.codehenge.net/blog’, hooks=dict(response=print_res)) job = grequests.send(req, grequests.Pool(1)) for i in range(10): print i Without the pool the .send() call will block … Read more

Asyncio vs. Gevent [closed]

“Simple” answer from real-world usage: Good thing about gevent — you can patch things, which means that you [theoretically] can use synchronous libraries. I.e. you can patch django. Bad thing about gevent — not everything can be patched, if you must use some DB driver that can’t be patched, you’re doomed Worst thing about gevent … Read more

How can I install the Python library ‘gevent’ on Mac OS X Lion

Don’t post the entire thing! That’s too much! 90% of the time, the first error is enough… gevent/libevent.h:9:19: error: event.h: No such file or directory This means that the library which provides the event.h header is not installed. The library is called libevent (website). In general, compilation errors like these are a flaw in the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)