[Tutor] Problem with threads

Kent Johnson kent37 at tds.net
Sat Feb 25 21:09:45 CET 2006


David Cohen wrote:
> Hi all,
> 
> I have a problem trying to use thread on python.
> I import the threading module and execute this:
> 
> def func_thread():
>     something...
> 
> new_thread = threading.Thread(target = func_thread)
> new_thread.start()
> 
> But the thread never really starts, just when I call the
> new_thread.join() method.
> Does anybody could help me?

More code would help. What you have shown looks fine. What does
func_thread() do? How do you know it isn't doing it? Here is a very
simple, working example based on your code:

import threading, time

def func_thread():
     while True:
         print 'threading'
         time.sleep(1)

new_thread = threading.Thread(target = func_thread)
new_thread.start()

print "main thread going away now"

Kent




More information about the Tutor mailing list