Stuck connection in Python 3.0b2 http.server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rs387

    Stuck connection in Python 3.0b2 http.server

    Hi All

    I've encountered a weird issue when migrating a web server to Python 3
    - the browser would wait forever without showing a page, displaying
    "Transferri ng data" in the status bar. I tracked it down to a
    reference cycle in my BaseHTTPRequest Handler descendant - one of the
    attributes stored a dict of methods. Removing the cycle made the
    problem go away.

    In Python 2.5.2 the code works fine either way.

    Here's a minimal example which runs in both 2.5 and 3.0 - to see stuck
    connections run as-is in 3.0 and navigate to http://localhost:8123; to
    fix this comment out "self.dummy = self" (alternatively reset
    self.dummy = None at the end of the __init__ method).

    Am I doing it wrong, or is this a bug?


    try:
    import http.server
    httpmodule = http.server
    except:
    import BaseHTTPServer
    httpmodule = BaseHTTPServer

    class BreakageRequest (httpmodule.Bas eHTTPRequestHan dler):
    def __init__(self, request, client_address, server):
    self.dummy = self # COMMENT THIS OUT to see the connection
    become unstuck
    httpmodule.Base HTTPRequestHand ler.__init__(se lf, request,
    client_address, server)
    def do_GET(self):
    self.send_respo nse(200)
    self.send_heade r("Content-Type", "applicatio n/xml")
    self.end_header s()
    self.wfile.writ e("<is_it_stu ck/>".encode('ut f-8'))

    srv = httpmodule.HTTP Server(('', 8123), BreakageRequest )
    srv.serve_forev er()
  • Fredrik Lundh

    #2
    Re: Stuck connection in Python 3.0b2 http.server

    rs387 wrote:
    I've encountered a weird issue when migrating a web server to Python 3
    - the browser would wait forever without showing a page, displaying
    "Transferri ng data" in the status bar. I tracked it down to a
    reference cycle in my BaseHTTPRequest Handler descendant - one of the
    attributes stored a dict of methods. Removing the cycle made the
    problem go away.
    >
    In Python 2.5.2 the code works fine either way.
    >
    Here's a minimal example which runs in both 2.5 and 3.0 - to see stuck
    connections run as-is in 3.0 and navigate to http://localhost:8123; to
    fix this comment out "self.dummy = self" (alternatively reset
    self.dummy = None at the end of the __init__ method).
    >
    Am I doing it wrong, or is this a bug?
    it's weird enough to deserve an issue over at http://bugs.python.org/,
    at least.

    it'd probably be a good idea to test this on 2.6rc as well.

    </F>

    Comment

    Working...