Noob can't make threads work

Steve Horsley shoot at the.moon
Tue Mar 1 15:20:48 EST 2005


Grant Edwards wrote:
> On 2005-03-01, Steve Horsley <shoot at the.moon> wrote:
> 
>>I am trying to start two threads to do some time consuming work. This is my
>>first stab at threading, and it isn't working as I expect. Instead of the 
>>threads starting when I call start(), they seem to run the target code as
>>part of the constructor call.
>>
>>Here is my test code...
>>
>>#!/usr/bin/python
>>
>>import time
>>import threading
>>
>>def fiddle():
>>    for n in range(3):
>>        print n
>>        time.sleep(1)
>>
>>print 'Creating threads...'
>>t1 = threading.Thread(target=fiddle())
>>t2 = threading.Thread(target=fiddle())
> 
> 
> t1 = threading.Thread(target=fiddle)
> t2 = threading.Thread(target=fiddle)


Doh! Slap that forehead! 

Of course, I was calling fiddle() and using the
return value (None) as the target argument. And
a Thread with a target of None does nothing
when start()ed.

Many thanks.
Steve



More information about the Python-list mailing list