Python django.core.servers.basehttp 模块,WSGIServer() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用django.core.servers.basehttp.WSGIServer()

项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def run(addr, port, wsgi_handler, ipv6=False, threading=False):
    server_address = (addr, port)
    if threading:
        httpd_cls = type(str('WSGIServer'), (socketserver.ThreadingMixIn, WSGIServer), {})
    else:
        httpd_cls = WSGIServer
    httpd = httpd_cls(server_address, SlimWSGIRequestHandler, ipv6=ipv6)
    if threading:
        # ThreadingMixIn.daemon_threads indicates how threads will behave on an
        # abrupt shutdown; like quitting the server by the user or restarting
        # by the auto-reloader. True means the server will not wait for thread
        # termination before it quits. This will make auto-reloader faster
        # and will prevent the need to kill the server manually if a thread
        # isn't terminating correctly.
        httpd.daemon_threads = True
    httpd.set_app(wsgi_handler)
    httpd.serve_forever()
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def _create_server(self, port):
        return WSGIServer((self.host, port), QuietWSGIRequestHandler)
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def _create_server(self, port):
        return WSGIServer((self.host, port), QuietWSGIRequestHandler, allow_reuse_address=False)
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def _create_server(self, port):
        return WSGIServer((self.host, port), QuietWSGIRequestHandler, allow_reuse_address=False)
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def _create_server(self, port):
        return WSGIServer((self.host, port), QuietWSGIRequestHandler)
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def _create_server(self, port):
        return WSGIServer((self.host, port), QuietWSGIRequestHandler)
项目:maas    作者:maas    | 项目源码 | 文件源码
def run(self, *args, **options):
        threading = options.get('use_threading', False)
        if threading:
            # This is a simple backport from Django's future
            # version to support threading.
            class ThreadedWSGIServer(ThreadingMixIn, WSGIServer):
                pass
            # Monkey patch basehttp.WSGIServer.
            setattr(basehttp, 'WSGIServer', ThreadedWSGIServer)

        start_up()
        return super(Command, self).run(*args, **options)
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def run(self):
        """
        Sets up the live server and databases, and then loops over handling
        http requests.
        """
        if self.connections_override:
            # Override this thread's database connections with the ones
            # provided by the main thread.
            for alias, conn in self.connections_override.items():
                connections[alias] = conn
        try:
            # Create the handler for serving static and media files
            handler = self.static_handler(_MediaFilesHandler(WSGIHandler()))

            # Go through the list of possible ports, hoping that we can find
            # one that is free to use for the WSGI server.
            for index, port in enumerate(self.possible_ports):
                try:
                    self.httpd = WSGIServer(
                        (self.host, port), QuietWSGIRequestHandler)
                except socket.error as e:
                    if (index + 1 < len(self.possible_ports) and
                            e.errno == errno.EADDRINUSE):
                        # This port is already in use, so we go on and try with
                        # the next one in the list.
                        continue
                    else:
                        # Either none of the given ports are free or the error
                        # is something else than "Address already in use". So
                        # we let that error bubble up to the main thread.
                        raise
                else:
                    # A free port was found.
                    self.port = port
                    break

            self.httpd.set_app(handler)
            self.is_ready.set()
            self.httpd.serve_forever()
        except Exception as e:
            self.error = e
            self.is_ready.set()