SimpleHTTPRequestHandler handling long lasting requests problem

Discussion in 'Python' started by Andy Leszczynski, Mar 10, 2005.

  1. 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.BaseHTTPRequestHandler):
    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,BaseHTTPServer.HTTPServer):
    pass

    if __name__ == '__main__':
    server_address = ('',80)
    httpd=myWebServer(server_address,SimpleHTTPRequestHandler)
    sa=httpd.socket.getsockname()
    print "Serving HTTP on", sa[0], "port", sa[1],"..."
    httpd.serve_forever()
     
    Andy Leszczynski, Mar 10, 2005
    #1
    1. Advertising

  2. 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.
     
    Andy Leszczynski, Mar 11, 2005
    #2
    1. Advertising

  3. Andy Leszczynski

    Steve Holden Guest

    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/
     
    Steve Holden, Mar 11, 2005
    #3
  4. 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.
     
    Andy Leszczynski, Mar 14, 2005
    #4
  5. 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.
     
    Andy Leszczynski, Mar 14, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve M
    Replies:
    5
    Views:
    574
    Yan-Hong Huang[MSFT]
    Jul 31, 2003
  2. Replies:
    0
    Views:
    587
  3. Mantas Miliukas

    Time out problems for long lasting actions

    Mantas Miliukas, Mar 9, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    130
    Mantas Miliukas
    Mar 9, 2005
  4. Alexander van Meerten
    Replies:
    3
    Views:
    125
    Janwillem Borleffs
    Oct 14, 2003
  5. Piotr Dobrogost
    Replies:
    3
    Views:
    249
    Piotr Dobrogost
    Apr 13, 2013
Loading...

Share This Page