简体   繁体   English

使用 uWSGI 运行时,multiprocessing.Process 阻塞了 return 语句

[英]multiprocessing.Process is blocking the return statement when running with uWSGI

I am running an API back and currently, I am using a subprocess.Popen .我正在运行 API ,目前,我正在使用subprocess.Popen As the called modules are pure python my idea is to run it with multiprocessing.Process or Pull .由于被调用的模块是纯 python 我的想法是使用multiprocessing.ProcessPull运行它。 The request is processed like this:请求是这样处理的:

  1. A request arrives at a Connexion endpoint请求到达Connexion端点
  2. Some preprocessing is done一些预处理完成
  3. The function is opened with Popen function 用 Popen 打开
  4. The request returns a 200 without waiting for 3. to finish请求返回 200 而无需等待 3. 完成

When replacing:更换时:

Popen(...)

with

p = Process(target=...)
p.start()

this happens to multiprocessing with uwsgi:这发生在使用uwsgi 的多处理中:

  1. A request arrives at a Connexion endpoint请求到达Connexion端点
  2. Some preprocessing is done一些预处理完成
  3. The function is opened with Process function 用进程打开
  4. The request returns a 200 immediately, but a second request to the same endpoint will require the previous 3 to finish.该请求立即返回 200,但对同一端点的第二个请求将需要前 3 个完成。

in if I run it on https://github.com/tiangolo/uwsgi-nginx-flask-docker :如果我在https://github.com/tiangolo/uwsgi-nginx-flask-docker上运行它:

... ...

  1. The request waits until 3 is finished and then returns a 200请求等到 3 完成,然后返回 200

It works as espected if I run the process with python -m... .如果我使用python -m...运行该过程,它会按预期工作。

My uwsgi.ini looks like this我的 uwsgi.ini 看起来像这样

 [uwsgi]
 module = myapp
 callable = app
 lazy-apps = true
 stats-http = true
 http = 127.0.0.1:8080

Your uwsgi.ini should enable threads, which are by default, blocked.您的 uwsgi.ini 应该启用默认情况下被阻止的线程。

Change it to the following将其更改为以下

[uwsgi]
module = myapp
callable = app
lazy-apps = true
stats-http = true
http = 127.0.0.1:8080
enable-threads = true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM