[Idle-dev] Bug in IDLE
Jonathan Lee
jlee@nucorar.com
Mon, 23 Jul 2001 13:32:57 -0500
Here's a bug/"undocumented feature" I found in the IDLE program. I didn't
find anything about it mentioned in the documentation, so I thought I would
inform you about it. Sorry for bothering you if you already know about it.
I'm running IDLE 0.8 with Python 2.1 under Windows 2000 Professional.
I was running an example program that I pulled out of a message on a SIG
list (full code included below) for the threading.py module and discovered
that under IDLE the program never completed. It seemed to get stuck in the
following loop under the 'main' conditional:
while threading.activeCount() > 1 :
print ".",
time.sleep(1)
At a command line prompt, the program took about 35 seconds to complete.
Under IDLE, I finally killed it after it still hadn't completed after ~20
minutes. Is there a different function that should be used as the loop
condition, is the activeCount() function including the IDLE threads in its
count, or is the execution speed under IDLE really that much slower for
this type of code?
Sincerely,
Jonathan Lee
2jlee*arkansas_net
<Replace the * and _ with the appropriate characters to contact me.>
P.S. Is there some place I could obtain example code for the various
modules included in the more recent editions of Python. The two modules
I've needed so far that I didn't find any example code for were the
"SocketServer" and the "threading" modules. I found the demo programs from
the python source code on SourceForge, but they only use the more primitive
"socket" and "thread" modules.
##################################################################
import urllib, time
import threading
retrieveDoc = 1
numPings = 20
numThreads = 5
url = 'http://www.foo.com/'
class ping ( threading.Thread ) :
def __init__ ( self, url, numPings, retrieveDoc=1 ) :
self.url = url
self.numPings = numPings
self.retrieveDoc = retrieveDoc
threading.Thread.__init__(self)
def run ( self ) :
StartTime = time.time()
for i in range(self.numPings):
page = urllib.urlopen ( self.url )
if self.retrieveDoc:
page.read()
page.close()
EndTime = time.time()
self.TotalTime = EndTime - StartTime
if __name__ == '__main__' :
threadList = []
for i in range(numThreads) :
thread = ping ( url, numPings, retrieveDoc )
threadList.append ( thread )
StartTime = time.time()
for thread in threadList :
thread.start()
while threading.activeCount() > 1 :
print ".",
time.sleep(1)
EndTime = time.time()
TotalTime = EndTime - StartTime
print
TotalPings = 0
ThreadTime = 0
for thread in threadList :
TotalPings = TotalPings + thread.numPings
ThreadTime = ThreadTime + thread.TotalTime
PingAvg = TotalPings / TotalTime
ResponseAvg = ThreadTime / TotalPings
print "Threads: ", numThreads
print "Pings:", TotalPings
print "Total time:", TotalTime
print "Pings per second:", PingAvg
print "Average response time (secs):", ResponseAvg