В чем разница между двумя способами запуска колбы? - PullRequest
0 голосов
/ 13 июня 2019

Я использовал два способа запуска приложения фляги

1, используйте "python app.py" напрямую

2, используйте "gunicorn -w 1 -b localhost: 5000 app:app "

тогда я распечатал стеки вызовов , Я знаю, что 2-й способ лучше, потому что он использует сервер wsgi и может использоваться в производственной среде, но я до сих пор не могу понять, в чем глубокая разница между стеками вызовов.

Может кто-нибудь сказать мне, в чем разница между этими двумя способами?

1

File "/usr/lib/python3.6/threading.py", line 884, in _bootstrap
self._bootstrap_inner()
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3.6/socketserver.py", line 651, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib/python3.6/socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.6/socketserver.py", line 721, in __init__
self.handle()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/werkzeug/serving.py", line 326, in handle
rv = BaseHTTPRequestHandler.handle(self)
File "/usr/lib/python3.6/http/server.py", line 418, in handle
self.handle_one_request()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/werkzeug/serving.py", line 361, in handle_one_request
return self.run_wsgi()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/werkzeug/serving.py", line 303, in run_wsgi
execute(self.server.app)
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/werkzeug/serving.py", line 291, in execute
application_iter = app(environ, start_response)
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/flask/app.py", line 2328, in __call__
return self.wsgi_app(environ, start_response)
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/flask/app.py", line 2311, in wsgi_app
response = self.full_dispatch_request()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/flask/app.py", line 1832, in full_dispatch_request
rv = self.dispatch_request()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/flask/app.py", line 1818, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "app.py", line 10, in hello
traceback.print_stack()

2

File "/home/wangxu/pyApp/flaskApp/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 61, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/app/base.py", line 223, in run
super(Application, self).run()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
Arbiter(self).run()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/arbiter.py", line 203, in run
self.manage_workers()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/arbiter.py", line 545, in manage_workers
self.spawn_workers()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/arbiter.py", line 616, in spawn_workers
self.spawn_worker()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.run()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 124, in run
self.run_for_one(timeout)
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 68, in run_for_one
self.accept(listener)
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 30, in accept
self.handle(listener, client, addr)
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 135, in handle
self.handle_request(listener, req, client, addr)
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/flask/app.py", line 2328, in __call__
return self.wsgi_app(environ, start_response)
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/flask/app.py", line 2311, in wsgi_app
response = self.full_dispatch_request()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/flask/app.py", line 1832, in full_dispatch_request
rv = self.dispatch_request()
File "/home/wangxu/pyApp/flaskApp/lib/python3.6/site-packages/flask/app.py", line 1818, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/wangxu/pyApp/flaskApp/app.py", line 10, in hello
s = traceback.print_stack()

1 Ответ

1 голос
/ 13 июня 2019
  • Один запускает 1 процесс, другой может запустить больше процессов, если вы укажете.
  • Один запускает приложение, которое непосредственно слушает запрос, другой запускает рабочих (s) wsgi, которые работают за gunicorn, илиможет работать за другим wsgi-совместимым сервером, например, веб-сервером, который также завершает SSL.

Существуют и другие различия, но приведенные выше, по-видимому, ключевые различия.

...