(beginner) question on threads...

Fred Pacquier fredp at mygale.org.nospam
Fri Aug 31 16:58:48 CEST 2001

Looking into threads, I've been toying with BaseHTTPServer again, to see if 
I could make it respond to several requests at a time (like serving a page 
while downloading a file, etc.).

Off to a bad start, I made the following simple-minded change :

in class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler) :

in def handle(self) :

the last line : method()  # generally self.do_GET()
becomes :       thread.start_new_thread(method, () )

This immediately breaks the module :-), as in :

Unhandled exception in thread:
Traceback (most recent call last):
  File "daft.py", line 308, in do_GET
  File "daft.py", line 293, in send_page
  File "daft.py", line 163, in send_response
    self.wfile.write("%s %s %s\r\n" %
  File "c:\python21\lib\socket.py", line 192, in write
  File "c:\python21\lib\socket.py", line 179, in flush
AttributeError: 'int' object has no attribute 'send'

Am I just misusing the thread library, or is the whole idea hopelessly 
naive (ie the vanilla HTTPServer is inherently not threadable) ? I just 
want to learn, certainly not rewrite Medusa/Zope & all the AsyncHTTPServers 
out there :-)

YAFAP : http://www.multimania.com/fredp/

More information about the Python-list mailing list