|
|
|
|
|
by mrbrowning
4697 days ago
|
|
> I think the first thing that should be mentioned in any introductory article on Python threads is that Python threads work great for IO concurrency but they won't help with CPU concurrency. Things like downloading files, sending data over a socket will work nicely. Python's threads certainly work acceptably for IO-bound purposes, but given the overhead of creating a real OS thread and the potential for GIL thrashing when using Python 2.x on a multicore machine, I'm not sure why you wouldn't favor a greenlet-based solution in most such cases, especially since you don't even really have to drop the threading idiom to do so. |
|
Not only do you get more threads with greenlet you also don't have to worry about a whole class of synchronization side-effects since a greenlet will only switch contexts on an IO operation. (Now some might argue that is bad since you could be calling a function and not know what happens in side or what might happen in the future so you should lock anyway).