[Tutor] Python threads

tpc at csua.berkeley.edu tpc at csua.berkeley.edu
Thu Jun 10 19:10:11 EDT 2004



On Thu, 10 Jun 2004, Danny Yoo wrote:

> I have to ask a silly question: why is the class threaded?  I don't see
> the need for the threading here.  Since threaded programming can be
> complicated, it might be a better idea to avoid it for this particular
> problem.
>

hi Danny, I created an application that indexes .mp3 and .wmv files
and, depending on user input, returns the files that have the
corresponding words in the filename, along with the file category
(i.e., Audio or Video) and the time-duration of the file.  I noticed a
marked increase in the time it took from the moment the user pressed
'Submit' to the results appearing in the browser when I ported
my application from Redhat Linux 9/Fedora Core 1/Fedora Core 2 to
Debian Linux.  I used hotshot profiler to arrive at an average of 2.302
seconds for the former to 42.315 seconds for the latter.  The reason I
had to go the multithreaded route was because I went to:

http://www.python.org/doc/current/lib/module-urllib.html

and at the bottom of the page you will notice:

"The urlopen() and urlretrieve() functions can cause arbitrarily long
delays while waiting for a network connection to be set up.  This means
that it is difficult to build an interactive Web client using these
functions without using threads."





More information about the Tutor mailing list