4 ms·
If you're after golang-style concurrency in python, I suggest looking at gevent. It uses "greenlets" - lightweight threads implemented in userspace - and monke
by ekimekim 7y ago
If you're after golang-style concurrency in python, I suggest looking at gevent.
It uses "greenlets" - lightweight threads implemented in userspace - and monkey patches the standard library to do cooperative multitasking. For example, when you call socket.recv(), under the hood it will register with the event loop to be woken up when that socket is readable, then yield to allow other greenlets to run while it waits.
(note this is slightly different to golang's concurrency, which works similarly but runs multiple OS threads so multiple goroutines can run at the same time)
The equivalent to "go fn(1, 2, 3)" in gevent is "gevent.spawn(fn, 1, 2, 3)". Any callable can be spawned this way, you don't need to pre-register functions as "startable" like in OP's library.
- luoyusang2007 7y agoYour opinion is great. Actually we want to combine "threading", "gevent" and "multiprocessing" together in this package. We can offer a unified API to handle different types of concurrency in your application if your application is light-weight and is not very performance-dependent. We don't know if it is necessary. Additionally, if you don't want a "startable" statement in your code, you can use our library in the following way: "go(fn)(arg1,arg2)". You don't have to declare that the function is startable. Happy 2020 anyhow~