Jul
11
Basic thread pools
Let's say you have a network server built around a single-threaded event loop—gevent, Twisted, asyncore, something simple you built on top of select.select, whatever. It's important to handle every event quickly. If you take 30 seconds responding to a requests from one connection, you can't deal with anyone else's requests, or accept new connections, for that whole 30 seconds.
But what if the request actually takes 30 seconds' worth of work to handle?
This is exactly what threads are for. You package up a job that does the 30 seconds of work and responds to the request when it's done, and kick it out of the event loop to run in parallel, then you can move on to the next event without waiting for it to finish.
The same thing applies to GUI programs.
But what if the request actually takes 30 seconds' worth of work to handle?
This is exactly what threads are for. You package up a job that does the 30 seconds of work and responds to the request when it's done, and kick it out of the event loop to run in parallel, then you can move on to the next event without waiting for it to finish.
The same thing applies to GUI programs.