3 ms·
I realize this is useful for cpu-bound computations; but for network-bound here is a REAL two-liner that will instantly make your program concurrent (not parall
by asperous 13y ago
I realize this is useful for cpu-bound computations; but for network-bound here is a REAL two-liner that will instantly make your program concurrent (not parallel):
from gevent import monkey
monkey.patch_all()
This is a lot lighter than processes. You can combine the two- use gevent to handle network, and then multiprocessing to handle cpu stuff!
- johtso 13y agoI've heard that using gevent with multiprocessing can cause problems, is that still the case?
- asperous 13y agoYou don't want multiprocessing to fork your process after gevent is loaded. If you can avoid that (like hold off on monkey patching) then it works great.
- inportb 13y agoI've used gevent in multiprocess situations, and it worked just fine. I did rig up my own gevent-based IPC, though. Just create a socketpair before forking, and attach some JSON-RPC (or protobuf/msgpack/etc) endpoints after.
- HeyImAlex 13y agoThere's even a gevented version of requests called grequests. The only thing about gevent is that the docs kind of suck, but their apis are pretty intuitive and the code itself is well documented.