当前位置: 首页>>代码示例>>Python>>正文


Python WSGIServer.serve_forever方法代码示例

本文整理汇总了Python中django.core.servers.basehttp.WSGIServer.serve_forever方法的典型用法代码示例。如果您正苦于以下问题:Python WSGIServer.serve_forever方法的具体用法?Python WSGIServer.serve_forever怎么用?Python WSGIServer.serve_forever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.servers.basehttp.WSGIServer的用法示例。


在下文中一共展示了WSGIServer.serve_forever方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: LiveServerThread

# 需要导入模块: from django.core.servers.basehttp import WSGIServer [as 别名]
# 或者: from django.core.servers.basehttp.WSGIServer import serve_forever [as 别名]
class LiveServerThread(threading.Thread):
    """
    Thread for running a live http server while the tests are running.
    """

    def __init__(self, host, possible_ports, static_handler, connections_override=None):
        self.host = host
        self.port = None
        self.possible_ports = possible_ports
        self.is_ready = threading.Event()
        self.error = None
        self.static_handler = static_handler
        self.connections_override = connections_override
        super(LiveServerThread, self).__init__()

    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()

    def terminate(self):
        if hasattr(self, 'httpd'):
            # Stop the WSGI server
            self.httpd.shutdown()
            self.httpd.server_close()
开发者ID:912,项目名称:M-new,代码行数:65,代码来源:testcases.py

示例2: run

# 需要导入模块: from django.core.servers.basehttp import WSGIServer [as 别名]
# 或者: from django.core.servers.basehttp.WSGIServer import serve_forever [as 别名]
def run(application, addr, port):
    httpd = WSGIServer((addr, port), WSGIRequestHandler, ipv6=False)
    httpd.set_app(application)
    httpd.serve_forever()
开发者ID:alswl,项目名称:weby,代码行数:6,代码来源:httpd.py

示例3: serve

# 需要导入模块: from django.core.servers.basehttp import WSGIServer [as 别名]
# 或者: from django.core.servers.basehttp.WSGIServer import serve_forever [as 别名]
def serve(view, host='localhost', port=6789):
    httpd = WSGIServer((host, port), WSGIRequestHandler)
    httpd.set_app(WSGIWrapper(view))
    httpd.serve_forever()
开发者ID:Mondego,项目名称:pyreco,代码行数:6,代码来源:allPythonContent.py

示例4: RequestHandler

# 需要导入模块: from django.core.servers.basehttp import WSGIServer [as 别名]
# 或者: from django.core.servers.basehttp.WSGIServer import serve_forever [as 别名]
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from colors import add_markup
from django.core.servers.basehttp import WSGIServer, WSGIRequestHandler, get_internal_wsgi_application


logpath = os.getenv('PYTHON_SERVICE_ARGUMENT')


class RequestHandler(WSGIRequestHandler):
    def log_message(self, format, *args):
        # Don't bother logging requests for admin images, or the favicon.
        if (self.path.startswith(self.admin_static_prefix)
                or self.path == '/favicon.ico'):
            return

        msg = "[%s] %s" % (self.log_date_time_string(), format % args)
        kivymarkup = add_markup(msg, args)
        with open(logpath, 'a') as fh:
            fh.write(kivymarkup + '\n')
            fh.flush()

server_address = ('0.0.0.0', 8000)
wsgi_handler = get_internal_wsgi_application()
httpd = WSGIServer(server_address, RequestHandler)
httpd.set_app(wsgi_handler)
httpd.serve_forever()
开发者ID:blagarde,项目名称:djandro,代码行数:29,代码来源:main.py


注:本文中的django.core.servers.basehttp.WSGIServer.serve_forever方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。