threads

Bart Nessux bart_nessux at hotmail.com
Tue Jan 27 20:38:51 EST 2004


Aahz wrote:
> In article <401706AB.6020703 at hotmail.com>,
> Bart Nessux  <bart_nessux at hotmail.com> wrote:
> 
>>Thank you both for the info on threads in Python it was very helpful to 
>>me, I've written something that I think can benefit from threading... 
>>here is the code, I copied this from a few books and a few Web examples 
>>and modified it to suit my test:
>>
>>class trivialthread(threading.Thread):
>>   def url_open(self):
>>      for x in xrange(999999):
>>         f = urllib.urlopen("http://xxx.xxx.xxx")
>>         f.read()
>>         f.close()
>>         print self, x
> 
> 
> Rename ``url_open()`` to ``run()``.  You might want to read the
> slideshow on my web site, paying particular attention to the examples.

Wow, that was a simple fix... thanks for the link. Threads are indeed 
powerful. It's hard to believe what a difference they can make. 
Question: is this equivalent to running the function in parallel? For 
example, say I open 15 shells and run the program... is that doing the 
same thing that threads do?




More information about the Python-list mailing list