Can Gevent be used in combination with real threads in CPython?

Question:

just wondering whether gevent coro-thread can work with real threading? perhaps I can write a program with multiple threads and each thread has some coroutines in them?

edited

both gevent.Threading and CPython threading have their down side. coroutines cannot utilize multiple CPUs, while CPython Threading performance is limited by the GIL when the number of threads is large.
I’m also working on a pure Python coroutine implementation similar to bluelet (although overhead may be larger than gevent), to add the ability to use coro and threading at the same time.

and I’m just wondering whether gevent or greenlet(https://pypi.python.org/pypi/greenlet) can achieve the coop ability with CPython threading.

Asked By: frostyplanet

||

Answers:

Gevent 1.0 should support having a Gevent main loop per thread, if that’s what you mean.

Also, gevent.threadpool allows running tasks in real threads in a gevent-compatible way:

threadpool = gevent.threadpool.ThreadPool()
result = threadpool.spawn(some_non_gevent_friendly_thing_such_as_file_io)

result.get()  # or use ThreadPool.apply/apply_e to get the result value immediately

You’ll find more information about gevent.threadpool by looking at https://github.com/gevent/gevent/blob/master/src/gevent/threadpool.py (or the doc once the doc for 1.0 becomes available in published/HTML form).

Answered By: Erik Kaplun