Пример #1
0
 def _run_wsgi(self, addr, port, wsgi_handler):
     server_address = (addr, port)
     httpd = WSGIServer(server_address, WSGIRequestHandler)
     httpd.set_app(wsgi_handler)
     #httpd.serve_forever()
     while not self.stop_requested:
         httpd.handle_request()        
Пример #2
0
    def run(self):
        self.lock.acquire()
        pidfile = os.path.join(tempfile.gettempdir(), 'lettuce-django.pid')
        if os.path.exists(pidfile):
            pid = int(open(pidfile).read())
            try:
                os.kill(pid, 9)

            except OSError:
                pass

            finally:
                os.unlink(pidfile)

        open(pidfile, 'w').write(unicode(os.getpid()))

        bound = False
        max_port = 65535

        connector = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        while not bound or self.port < max_port:
            try:
                connector.connect((self.address, self.port))
                self.port += 1

            except socket.error:
                bound = True
                break

        if bound:
            try:
                server_address = (self.address, self.port)
                httpd = WSGIServer(server_address, MutedRequestHandler)
                bound = True
            except WSGIServerException:
                bound = False

        if not bound:
            raise LettuceServerException(
                "the port %d already being used, could not start " \
                "django's builtin server on it" % self.port
            )


        handler = StopabbleHandler(WSGIHandler())
        if 'django.contrib.admin' in settings.INSTALLED_APPS:
            admin_media_path = ''
            handler = AdminMediaHandler(handler, admin_media_path)
            print "Preparing to server django's admin site static files..."

        httpd.set_app(handler)

        global keep_running
        while keep_running:
            call_hook('before', 'handle_request', httpd, self)
            httpd.handle_request()
            call_hook('after', 'handle_request', httpd, self)
            if self.lock.locked():
                self.lock.release()
Пример #3
0
    def run(self):
        self.lock.acquire()
        pidfile = os.path.join(tempfile.gettempdir(), 'lettuce-django.pid')
        if os.path.exists(pidfile):
            pid = int(open(pidfile).read())
            try:
                os.kill(pid, 9)

            except OSError:
                pass

            finally:
                os.unlink(pidfile)

        open(pidfile, 'w').write(unicode(os.getpid()))

        bound = False
        max_port = 65535

        connector = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        while not bound or self.port < max_port:
            try:
                connector.connect((self.address, self.port))
                self.port += 1

            except socket.error:
                bound = True
                break

        if bound:
            try:
                server_address = (self.address, self.port)
                httpd = WSGIServer(server_address, MutedRequestHandler)
                bound = True
            except WSGIServerException:
                bound = False

        if not bound:
            raise LettuceServerException(
                "the port %d already being used, could not start " \
                "django's builtin server on it" % self.port
            )


        handler = StopabbleHandler(WSGIHandler())
        if 'django.contrib.admin' in settings.INSTALLED_APPS:
            admin_media_path = ''
            handler = AdminMediaHandler(handler, admin_media_path)
            print "Preparing to server django's admin site static files..."

        httpd.set_app(handler)

        global keep_running
        while keep_running:
            call_hook('before', 'handle_request', httpd, self)
            httpd.handle_request()
            call_hook('after', 'handle_request', httpd, self)
            if self.lock.locked():
                self.lock.release()
Пример #4
0
    def run(self):
        self.lock.acquire()
        pidfile = os.path.join(tempfile.gettempdir(), 'lettuce-django.pid')
        if os.path.exists(pidfile):
            pid = int(open(pidfile).read())
            try:
                os.kill(pid, 9)

            except OSError:
                pass

            finally:
                os.unlink(pidfile)

        open(pidfile, 'w').write(unicode(os.getpid()))

        connector = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        try:
            s = connector.connect((self.address, self.port))
            self.lock.release()
            os.kill(os.getpid(), 9)
        except socket.error:
            pass

        finally:
            self.lock.release()

        try:
            server_address = (self.address, self.port)
            httpd = WSGIServer(server_address, MutedRequestHandler)
        except WSGIServerException:
            raise LettuceServerException(
                "the port %d already being used, could not start " \
                "django's builtin server on it" % self.port,
            )

        handler = WSGIHandler()
        if self.should_serve_admin_media():
            admin_media_path = ''
            handler = AdminMediaHandler(handler, admin_media_path)

        if self.should_serve_static_files():
            handler = StaticFilesHandler(handler)

        httpd.set_app(handler)

        global keep_running
        while keep_running:
            call_hook('before', 'handle_request', httpd, self)
            httpd.handle_request()
            call_hook('after', 'handle_request', httpd, self)
            try:
                self.lock.release()
            except ValueError:
                pass
Пример #5
0
 def run(self):
     try:
         handler = AdminMediaHandler(WSGIHandler())
         server_address = (config.HOST, config.PORT)
         httpd = WSGIServer(server_address, SilentWSGIRequestHandler)
         httpd.set_app(handler)
         while self.running.isSet():
             httpd.handle_request()
         httpd.server_close()
     except WSGIServerException, e:
         pass
Пример #6
0
    def run(self):
        self.lock.acquire()
        pidfile = os.path.join(tempfile.gettempdir(), 'lettuce-django.pid')

        if os.path.exists(pidfile):
            pid = int(open(pidfile).read())
            try:
                os.kill(pid, 9)

            except OSError:
                pass

            finally:
                os.unlink(pidfile)

        open(pidfile, 'w').write(unicode(os.getpid()))

        bound = False
        max_port = 65535
        while not bound or self.port > max_port:
            try:
                server_address = (self.address, self.port)
                httpd = WSGIServer(server_address, MutedRequestHandler)
                bound = True
            except WSGIServerException:
                self.port += 1

        if not bound:
            raise LettuceServerException(
                "the port %d already being used, could not start " \
                "django's builtin server on it" % self.port
            )

        httpd.set_app(StopabbleHandler(WSGIHandler()))
        self.lock.release()

        global keep_running
        while keep_running:
            httpd.handle_request()
Пример #7
0
 def handle_request(self, timeout=1.0):
     reads, writes, errors = (self, ), (), ()
     reads, writes, errors = select.select(reads, writes, errors, timeout)
     if reads:
         WSGIServer.handle_request(self)
Пример #8
0
 def handle_request(self, timeout=1.0):
     reads, writes, errors = (self, ), (), ()
     reads, writes, errors = select.select(reads, writes, errors, timeout)
     if reads:
         WSGIServer.handle_request(self)
Пример #9
0
    def run(self):
        self.lock.acquire()
        pidfile = os.path.join(tempfile.gettempdir(), "lettuce-django.pid")
        if os.path.exists(pidfile):
            pid = int(open(pidfile).read())
            try:
                os.kill(pid, 9)

            except OSError:
                pass

            finally:
                os.unlink(pidfile)

        open(pidfile, "w").write(unicode(os.getpid()))

        self.configure_mail_queue()

        connector = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        try:
            s = connector.connect((self.address, self.port))
            self.lock.release()
            os.kill(os.getpid(), 9)
        except socket.error:
            pass

        finally:
            self.lock.release()

        try:
            server_address = (self.address, self.port)
            httpd = WSGIServer(server_address, MutedRequestHandler)
        except socket.error:
            raise LettuceServerException(
                "the port %d already being used, could not start " "django's builtin server on it" % self.port
            )

        handler = WSGIHandler()
        if self.should_serve_admin_media():
            if not AdminMediaHandler:
                raise LettuceServerException(
                    "AdminMediaHandler is not available in this version of "
                    "Django. Please set LETTUCE_SERVE_ADMIN_MEDIA = False "
                    "in your Django settings."
                )
            admin_media_path = ""
            handler = AdminMediaHandler(handler, admin_media_path)

        if self.should_serve_static_files():
            handler = StaticFilesHandler(handler)

        httpd.set_app(handler)

        global keep_running
        while keep_running:
            call_hook("before", "handle_request", httpd, self)
            httpd.handle_request()
            call_hook("after", "handle_request", httpd, self)
            try:
                self.lock.release()
            except ValueError:
                pass
Пример #10
0
    def run(self):
        self.lock.acquire()
        pidfile = os.path.join(tempfile.gettempdir(), "lettuce-django.pid")
        if os.path.exists(pidfile):
            pid = int(open(pidfile).read())
            try:
                os.kill(pid, 9)

            except OSError:
                pass

            finally:
                os.unlink(pidfile)

        open(pidfile, "w").write(unicode(os.getpid()))

        bound = False
        max_port = 65535

        connector = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        while not bound or self.port < max_port:
            try:
                connector.connect((self.address, self.port))
                self.port += 1

            except socket.error:
                bound = True
                break

        if bound:
            try:
                server_address = (self.address, self.port)
                httpd = WSGIServer(server_address, MutedRequestHandler)
                bound = True
            except WSGIServerException:
                bound = False

        if not bound:
            raise LettuceServerException(
                "the port %d already being used, could not start " "django's builtin server on it" % self.port
            )

        handler = WSGIHandler()
        if self.should_serve_admin_media():
            admin_media_path = ""
            handler = AdminMediaHandler(handler, admin_media_path)

        if self.should_serve_static_files():
            handler = StaticFilesHandler(handler)

        httpd.set_app(handler)

        global keep_running
        while keep_running:
            call_hook("before", "handle_request", httpd, self)
            httpd.handle_request()
            call_hook("after", "handle_request", httpd, self)
            try:
                self.lock.release()
            except ValueError:
                pass