Threading question

Dave Brueck dbrueck at edgix.com
Thu Apr 12 14:14:07 EDT 2001


> tmp = Thread(target=os.system(other_script.py))
>

Hi Jared,

You're pretty close. Try something like this instead:

tmp = Thread(target=os.system, args=('python other_script.py',))
tmp.start()

or just

Thread(target=os.system, args=('python other_script.py',)).start()


The original way you were doing it was creating a thread who's target was
the _result_ of calling os.system (ie - it called os.system right then).
Also, the new thread was never started - Thread() is a thread constructor,
after you've created the thread you have to start it.

One last thing: the args parameter to the Thread constructor is a tuple, so
if your function takes only one parameter be sure to write it as (x,)
instead of just (x) so that Python realizes you really want a tuple there.

Hope that helps,
Dave





More information about the Python-list mailing list