[Tutor] Differences in running a multithreaded script under IDLE and otherwise
Hans.Dushanthakumar at navman.com
Thu Aug 25 23:42:49 CEST 2005
I'm using the same version (2.4.1) under Win XP. The program works as
expected (ie prints "run: <k>" a few times, and then just goes dead - no
errors. Having said that, I did see one instance where it ran to
completion under IDLE. So looks like the behaviour is not consistent.
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of Kent Johnson
Sent: Thursday, 25 August 2005 11:23 p.m.
Cc: tutor at python.org
Subject: Re: [Tutor] Differences in running a multithreaded script under
IDLE and otherwise
Hans Dushanthakumar wrote:
> 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?
> import threading
> class incr_num(threading.Thread):
> num = ''
> def __init__(self, local_num):
> global num
> 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)
> print "Wait for thread to finish"
> print "Thread finished"
> raw_input("Press enter")
> Tutor maillist - Tutor at python.org
Tutor maillist - Tutor at python.org
More information about the Tutor