Пример #1
0
    def _run_server(self, app):
        """Run a wsgi server in a separate thread"""
        ip, port = _free_port()
        self.app = app = WSGIApplication(app, (ip, port))

        def run():
            httpd = simple_server.make_server(ip,
                                              port,
                                              app,
                                              server_class=WSGIServer,
                                              handler_class=WSGIRequestHandler)
            httpd.serve_forever()

        app.thread = threading.Thread(target=run)
        app.thread.start()
        conn = HTTPConnection(ip, port)
        time.sleep(.5)
        for i in range(100):
            try:
                conn.request('GET', '/__application__')
                conn.getresponse()
            except (socket.error, CannotSendRequest):
                time.sleep(.3)
            else:
                break
Пример #2
0
 def close(self):
     """Close WSGI server if needed"""
     if self.app:
         conn = HTTPConnection(*self.app.bind)
         for i in range(100):
             try:
                 conn.request('GET', '/__kill_application__')
                 conn.getresponse()
             except socket.error:
                 conn.close()
                 break
             else:
                 time.sleep(.3)
Пример #3
0
 def close(self):
     """Close WSGI server if needed"""
     if self.app:
         conn = HTTPConnection(*self.app.bind)
         for i in range(100):
             try:
                 conn.request('GET', '/__kill_application__')
                 conn.getresponse()
             except socket.error:
                 conn.close()
                 break
             else:
                 time.sleep(.3)
Пример #4
0
    def _run_server(self, app):
        """Run a wsgi server in a separate thread"""
        ip, port = _free_port()
        self.app = app = WSGIApplication(app, (ip, port))

        def run():
            httpd = simple_server.make_server(
                            ip, port, app,
                            server_class=WSGIServer,
                            handler_class=WSGIRequestHandler)
            httpd.serve_forever()

        app.thread = threading.Thread(target=run)
        app.thread.start()
        conn = HTTPConnection(ip, port)
        time.sleep(.5)
        for i in range(100):
            try:
                conn.request('GET', '/__application__')
                conn.getresponse()
            except (socket.error, CannotSendRequest):
                time.sleep(.3)
            else:
                break