[Tutor] Differences in running a multithreaded script under IDLE and otherwise

Kent Johnson kent37 at tds.net
Thu Aug 25 13:22:36 CEST 2005


Hans Dushanthakumar wrote:
> Hi,
>    While running the foll script by double-clicking it (under WinXP), it
> runs as expected. However, when I run it via IDLE, it hangs after a few
> secs (no runtime errors - just hangs). Why does this happen?

It works for me in IDLE with Python 2.4.1 on Win2k. What version of Python do you have? Do you get any output at all?

Kent

> 
> Cheers
> Hans
> 
> import threading
> 
> class incr_num(threading.Thread):
>     num = ''
>     
>     def __init__(self, local_num):
>         global num
>         threading.Thread.__init__(self)
>         num = local_num
>         print "__init__: ", num
>         
>     def run(self):
>         global num
>         for k in range (20):
>             print "run: ", num
>             num = num + 1
> 
> incr_num_thread = incr_num(501)
> incr_num_thread.start()
> 
> print "Wait for thread to finish"
> incr_num_thread.join()
> print "Thread finished"
> 
> raw_input("Press enter")
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



More information about the Tutor mailing list