4 ms·
Because with asyncio you can run on one thread. Before, you needed multiple threads, or else incur high I/O costs. But then you have to manage your shared stat
by paulddraper 10y ago
Because with asyncio you can run on one thread.
Before, you needed multiple threads, or else incur high I/O costs. But then you have to manage your shared state across threads, hence locks.
Their code is now probably async single threaded code, like JS, where locks are irrelevant.
- ddorian43 10y agoBut don't threads run cpu-stuff in 1 thread, by not switching? (in python) The same as async but more overhead/slower.
- paulddraper 10y agoOnly one thread runs at a time because of the GIL, but the threads can preempt each other wherever between opcodes (http://effbot.org/zone/thread-synchronization.htm#atomic-operations http://effbot.org/zone/thread-synchronization.htm#atomic-ope...) Imagine two threads running a += 1 That's four opcodes. Only one operation will run at a time, but one thread might preempt the other midway through the four operations, and `a` will have been incremented by 1, not two. In some sense, mulithreading with Python's GIL is the worst of both worlds: you can use only one CPU, but you still need to account for concurrent state mutation. (Of course, it doesn't have the function color problem of asyncio http://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/ http://journal.stuffwithstuff.com/2015/02/01/what-color-is-y...)