(beginner) question on threads...
Fred Pacquier
fredp at mygale.org.nospam
Fri Aug 31 10:58:48 EDT 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
self.send_page(INDEX)
File "daft.py", line 293, in send_page
self.send_response('200')
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
self.flush()
File "c:\python21\lib\socket.py", line 179, in flush
self._sock.send(self._wbuf)
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 :-)
TIA,
fp
--
YAFAP : http://www.multimania.com/fredp/
More information about the Python-list
mailing list