[Tutor] : Threads?
Orri Ganel
singingxduck at gmail.com
Fri Oct 21 21:12:08 CEST 2005
Kent Johnson wrote:
>Orri Ganel wrote:
>
>
>>Hello all,
>>
>>I've been working on a program for a week or two now that will convert
>>all the wav files in a folder to mp3s, filling the id3 tags with the
>>correct information as collected from gracenote.com. This part works
>>fine. However, the actual conversion to mp3 takes between 30 and 50
>>seconds per song, so it's usually about 10 minutes per album. With this
>>in mind, I thought, why not try to use threads so all the conversions
>>happen simultaneously? That way, the whole album will take between 30
>>and 50 seconds. Unfortunately, I can't seem to get a working threaded
>>version that significantly reduces the time involved . . . The
>>
>>
>
>The only part you are doing in a thread is the actual conversion. This is likely to be CPU-intensive so running it in multiple threads may not help - you still have only the one CPU to run on. To the extent that you can overlap disk I/O in one conversion with processing in another you may get a win; on the other hand you could just as well have contention for the disk as you try to read and write a bunch of files at the same time.
>
>The fetch from gracenote.com seems like a better candidate for threading because there is some latency...but the total time is still probably small compared to the conversion time.
>
>Maybe if you have multiple CPUs you can get a speedup by using as many threads as CPUs...I'm not sure how os.system() behaves in this case. You may have to explicitly fork to get a new process.
>
>Hmm...come to think of it, os.system() may block other threads, I don't know...you could try subprocess.Popen() instead.
>
>Kent
>
Thanks for the tip. Unfortunately, I only have 1 CPU and not the
slightest idea how to code for multiple CPUs in any case. Looks like
I'll just hafta deal with a 10-minute time per album.
--
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.
More information about the Tutor
mailing list