我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用werkzeug.serving.run_simple()。
def serve(cwd, app, port): sys.path.insert(0, cwd) wsgi_fqn = app.rsplit('.', 1) wsgi_fqn_parts = wsgi_fqn[0].rsplit('/', 1) if len(wsgi_fqn_parts) == 2: sys.path.insert(0, os.path.join(cwd, wsgi_fqn_parts[0])) wsgi_module = importlib.import_module(wsgi_fqn_parts[-1]) wsgi_app = getattr(wsgi_module, wsgi_fqn[1]) # Attempt to force Flask into debug mode try: wsgi_app.debug = True except: # noqa: E722 pass os.environ['IS_OFFLINE'] = 'True' serving.run_simple( 'localhost', int(port), wsgi_app, use_debugger=True, use_reloader=True, use_evalex=True)
def test_app(environ, start_response): """Simple test application that dumps the environment. You can use it to check if Werkzeug is working properly: .. sourcecode:: pycon >>> from werkzeug.serving import run_simple >>> from werkzeug.testapp import test_app >>> run_simple('localhost', 3000, test_app) * Running on http://localhost:3000/ The application displays important information from the WSGI environment, the Python interpreter and the installed libraries. """ req = Request(environ, populate_request=False) if req.args.get('resource') == 'logo': response = logo else: response = Response(render_testapp(req), mimetype='text/html') return response(environ, start_response)
def run_dev_server(application): servers = [] def tracking_make_server(*args, **kwargs): srv = real_make_server(*args, **kwargs) servers.append(srv) return srv serving.make_server = tracking_make_server try: t = Thread(target=serving.run_simple, args=('localhost', 0, application)) t.setDaemon(True) t.start() time.sleep(0.25) finally: serving.make_server = real_make_server if not servers: return None, None server, = servers ip, port = server.socket.getsockname()[:2] if ':' in ip: ip = '[%s]' % ip return server, '%s:%d' % (ip, port)