469,599 Members | 2,794 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,599 developers. It's quick & easy.

BaseHTTPServer and keep-alive (evil hack problem)

This is called "evil hack problem" because my problems are due to me
trying to do an evil hack. Please don't judge me, just believe that
there are reasons for what I'm trying to do :-)

I've got a problem with BaseHTTPServer. I am trying to keep a
connection alive so that I can send data down it. At the moment, I
have subclassed BaseHTTPRequestHandler like this:
def do_POST(self):
body =
self.rfile.read(int(self.headers.getheader("conten t-length")))

# handle the message.
pm.handle_message(body, self.client_address[0],
debug("sending keep-alive header")
self.send_header("Connection", "keep-alive")
The handle_message method puts the wfile into a global map. When the
server wants to send more data, it just writes to the wfile. This
occurs in a separate thread.
So the do_POST method swiftly returns. I send the "keep-alive" header
because it seems to set connection_closed to 0 in the
BaseHTTPRequestHandler code, rather than because the client needs to
hear it.

However, when I try and write data to the wfile, I get:
Exception in thread Thread-3:Traceback (most recent call last):
File "/usr/lib/python2.3/threading.py", line 442, in __bootstrap
File "/usr/lib/python2.3/threading.py", line 422, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/dhughj/blogfish/src/PeerManager.py", line 267, in
File "/usr/lib/python2.3/socket.py", line 254, in write
File "/usr/lib/python2.3/socket.py", line 241, in flush
AttributeError: 'NoneType' object has no attribute 'sendall'
Can anyone help me to keep the connection alive at both ends, or
explain why at the moment the server is closing the conenection?

Thanks a lot.

Jul 18 '05 #1
1 3865
On 26 Jul 2004 06:35:37 -0700, rumours say that hu********@yahoo.co.uk
(David) might have written:


ICBW, but I think BaseHTTPServer is HTTP/1.0 compatible, not HTTP/1.1
--so at the end of every request, the socket is closed.
TZOTZIOY, I speak England very best,
"Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Joshua W. Biagio | last post: by
1 post views Thread by Yin | last post: by
2 posts views Thread by Simon Wittber | last post: by
2 posts views Thread by Andy Leszczynski | last post: by
1 post views Thread by Adam Atlas | last post: by
4 posts views Thread by amfr | last post: by
reply views Thread by Jeff Gercken | last post: by
reply views Thread by Ron Garret | last post: by
reply views Thread by samwyse | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.