#!/usr/local/bin/python '''This program demonstrates a crash in python 2.4.1 on Debian w/2.6 kernel. ''' import signal, sys, threading, time, urllib2 class WellBehavedClient: '''A well-behaved client. It tries to follow all the HTTP rules properly. ''' def __init__ (self): self._url = 'http://www.python.org' def run (self): '''Run, repeating forever. ''' while True: self.runOnce () def runOnce (self): '''Fetch one file, reading it very slowly (just to avoid swamping the server). ''' sys.stderr.write ('c') connection = urllib2.urlopen (self._url) sys.stderr.write ('C') while True: data = connection.read (10) sys.stderr.write ('.') time.sleep (1.0) if not data: break def run (threadCount=10): '''Launch a barrage of clients; each running in its own daemon thread. Return the list of client threads. ''' print 'Using %d threads' % threadCount # Make a list of clients: clients = [WellBehavedClient () for i in range (threadCount)] # Create a list of threads; each thread is poised to execute one of the clients: threads = [threading.Thread (target=client.run, args=()) for client in clients] # Start the threads: for thread in threads: thread.setDaemon (True) thread.start () # Block until all of the threads have finished (or a signal is received): time.sleep (30000) #for thread in threads: # thread.join (1.0) run (10) # N.B. the run() function is called when this module is imported or executed.