Threads and temporary files
gagsl-py2 at yahoo.com.ar
Sat Mar 14 04:01:07 CET 2009
En Fri, 13 Mar 2009 19:07:46 -0200, aiwarrior <zubeido at yahoo.com.br>
> I recently am meddling with threads and wanted to make a threaded
> class that instead of processing anything just retrieves data from a
> file and returns that data to a main thread that takes all the
> gathered data and concatenates it sequentially.
> An example is if we want to get various ranges of an http resource in
The usual way to communicate between threads is using a Queue object.
Instead of (create a thread, do some work, exit/destroy thread) you could
create the threads in advance (a "thread pool" of "worker threads") and
make them wait for some work to do from a queue (in a quasi-infinite
loop). When work is done, they put results in another queue. The main
thread just places work units on the first queue; another thread
reassembles the pieces from the result queue. For an I/O bound application
like yours, this should work smoothly.
You should be able to find examples on the web - try the Python Cookbook.
More information about the Python-list