Python django.core.servers.basehttp.WSGIServer() Examples

The following are 5 code examples of django.core.servers.basehttp.WSGIServer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.core.servers.basehttp , or try the search function .
Example #1
Source File: testcases.py    From python with Apache License 2.0 5 votes vote down vote up
def _create_server(self):
        return WSGIServer((self.host, self.port), QuietWSGIRequestHandler, allow_reuse_address=False) 
Example #2
Source File: testcases.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def _create_server(self, port):
        return WSGIServer((self.host, port), QuietWSGIRequestHandler) 
Example #3
Source File: testcases.py    From python2017 with MIT License 5 votes vote down vote up
def _create_server(self):
        return WSGIServer((self.host, self.port), QuietWSGIRequestHandler, allow_reuse_address=False) 
Example #4
Source File: runserver.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
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().run(*args, **options) 
Example #5
Source File: testcases.py    From GTDWeb with GNU General Public License v2.0 4 votes vote down vote up
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()