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


Python WSGIServer.shutdown方法代码示例

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


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

示例1: GaeTestServer

# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import shutdown [as 别名]
class GaeTestServer(object):

    def __init__(self):
        self.sdk_path = resolve_sdk_path()
        print 'python sdk found', self.sdk_path
        sys.path.insert(0, self.sdk_path)
        import dev_appserver
        dev_appserver.fix_sys_path()
        sys.path.insert(0, 'src')
        self.testbed = None
        self.httpd = None

    def boot_gae(self):
        from google.appengine.api import memcache
        from google.appengine.ext import ndb
        from google.appengine.ext import testbed
        from google.appengine.datastore import datastore_stub_util
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=0)
        self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
        self.testbed.init_memcache_stub()

    def boot_web(self, port, app):
        self.port = port
        self.httpd = WSGIServer(('localhost', port), WSGIRequestHandler)
        self.httpd.set_app(app)

    def server_forever_background(self):
        self.thread = threading.Thread(target=self.httpd.serve_forever)
        self.thread.start()

    def server_forever(self):
        self.httpd.serve_forever()

    def shutdown(self):
        if self.testbed:
            self.testbed.deactivate()
        if self.httpd:
            self.httpd.shutdown()
            self.httpd = None
开发者ID:murer,项目名称:gaetestz,代码行数:43,代码来源:gae_server_test.py

示例2: _HTTPServer

# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import shutdown [as 别名]
class _HTTPServer(bottle.ServerAdapter):
    """
    Reimplement bottle's WSGIRefServer. Override the request handler class and
    add a stop() method for cleanly shutting down the server.
    """
    srv = None
    app = None

    def run(self, handler):
        # Handle the TIME_WAIT state for quick server restarts
        WSGIServer.allow_reuse_address = 1

        # Create the server and start it
        self.srv = WSGIServer((self.host, self.port), _HTTPRequestHandler)
        self.srv.set_app(self.app)
        try:
            self.srv.serve_forever()
        finally:
            self.srv.server_close()

    def stop(self):
        if self.srv:
            self.srv.shutdown()
开发者ID:dtroyer,项目名称:dwarf,代码行数:25,代码来源:api_server.py


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