By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,002 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,002 IT Pros & Developers. It's quick & easy.

SimpleHTTPRequestHandler handling long lasting requests problem

P: n/a

I need a HTTP server handling long lasting requests e.g. 10-30 seconds.
Below is a pice of the code. In order to make the server reponsive while
handling othere requests I use SocketServer.ThreadingMixIn.

However the problem is the it does not work out. I checked thet a new
thread is created for each new connection new, but the main loop seems
to be frozen until the prevoius handling ends.

What could go wrong?

Thanks, Andy

* * *

import os
import time
import BaseHTTPServer
import SocketServer
import threading
import sys

class
SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRe questHandler):
def do_GET(self):
response="aaaaaaaaaaaaaaaa"+str(time.time())
self.send_response(200)
self.send_header("Content-type",'text/plain')

self.send_header("Content-Length",len(response))
self.end_headers()
time.sleep(10) #simulation of the processing
self.wfile.write(response)

def do_POST(self):
self.do_GET()

class
myWebServer(SocketServer.ThreadingMixIn,BaseHTTPSe rver.HTTPServer):
pass

if __name__ == '__main__':
server_address = ('',80)
httpd=myWebServer(server_address,SimpleHTTPRequest Handler)
sa=httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1],"..."
httpd.serve_forever()
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Sorry for questioning Python :-) - it turned out that this is a problem
with Mozilla. For some reason it holds up with opening second connection
to given host until the previous one is completed. Interestingly enough,
IE works better with Python multi threaded server in that regard.

Thx, A.
Jul 18 '05 #2

P: n/a
Andy Leszczynski wrote:
Sorry for questioning Python :-) - it turned out that this is a problem
with Mozilla. For some reason it holds up with opening second connection
to given host until the previous one is completed. Interestingly enough,
IE works better with Python multi threaded server in that regard.

Thx, A.


Try switching keepalives off, or falling back to HTTP 1.0 - ironically
it may be the attempt to use the same connection for both pieces of
content that holds things up.

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 18 '05 #3

P: n/a
Steve Holden wrote:
Andy Leszczynski wrote:
Sorry for questioning Python :-) - it turned out that this is a
problem with Mozilla. For some reason it holds up with opening second
connection to given host until the previous one is completed.
Interestingly enough, IE works better with Python multi threaded
server in that regard.

Thx, A.

Try switching keepalives off, or falling back to HTTP 1.0 - ironically
it may be the attempt to use the same connection for both pieces of
content that holds things up.

regards
Steve


I tested it before and it did not work either. Have to try HTTP 1.0 thouh.

Thanks, A.
Jul 18 '05 #4

P: n/a
Steve Holden wrote:
Andy Leszczynski wrote:
Sorry for questioning Python :-) - it turned out that this is a
problem with Mozilla. For some reason it holds up with opening second
connection to given host until the previous one is completed.
Interestingly enough, IE works better with Python multi threaded
server in that regard.

Thx, A.

Try switching keepalives off, or falling back to HTTP 1.0 - ironically
it may be the attempt to use the same connection for both pieces of
content that holds things up.

regards
Steve


I tested it before and it did not work either. Have to try HTTP 1.0 thouh.

Thanks, A.
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.