Thread Question

Ritesh Raj Sarraf rrs at researchut.com
Wed Aug 2 14:00:22 EDT 2006


Hi,

I have this following situation:

        #INFO: Thread Support
        # Will require more design thoughts
        from Queue import Queue
        from threading import Thread, currentThread
        
        NUMTHREADS = variables.options.num_of_threads
        
        def run(request, response, func=download_from_web):
            '''Get items from the request Queue, process them
            with func(), put the results along with the
            Thread's name into the response Queue.
        
            Stop running once an item is None.'''
        
            name = currentThread().getName()
            while 1:
                item = request.get()
                (sUrl, sFile, download_size, checksum) = stripper(item)
                if item is None:
                    break
                response.put((name, func(sUrl, sFile, sSourceDir, None)))

My download_from_web() returns True or False depending upon whether the download
was successful or failed. How can I check that in the above code ?

One other question I had,
If my user passes the --zip option, download_from_web() internally (when the
download is successful) zips the downloaded data to a zip file. Since in case
of threading there'll be multiple threads, and say if one of the thread
completes 2 seconds before others and is doing the zipping work:
What will the other thread, at that moment do, if it completes while the
previous thread is doing the zipping work ?

Thanks,
Ritesh



Justin  Azoff on Thursday 27 Jul 2006 22:33 wrote:

> Ritesh Raj Sarraf wrote:
> [snip]
>> for item in list_items:
>>     download_from_web(item)
>>
>> This way, one items is downloaded at a time.
>>
>> I'm planning to implement threads in my application so that multiple
>> items can be downloaded concurrently. I want the thread option to be
>> user-defined.
> [snip]
> 
> See my post about the iterthreader module I wrote...
>
http://groups.google.com/group/comp.lang.python/browse_frm/thread/2ef29fae28cf44c1/
> 
> for url, result in Threader(download_from_web, list_items):
>     print url, result
>     #...
> 

-- 
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
"Necessity is the mother of invention."
"Stealing logic from one person is plagiarism, stealing from many is research."
"The great are those who achieve the impossible, the petty are those who
cannot - rrs"




More information about the Python-list mailing list