繁体   English   中英

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

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

我正在运行 API ,目前,我正在使用subprocess.Popen 由于被调用的模块是纯 python 我的想法是使用multiprocessing.ProcessPull运行它。 请求是这样处理的:

  1. 请求到达Connexion端点
  2. 一些预处理完成
  3. function 用 Popen 打开
  4. 请求返回 200 而无需等待 3. 完成

更换时:

Popen(...)

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

这发生在使用uwsgi 的多处理中:

  1. 请求到达Connexion端点
  2. 一些预处理完成
  3. function 用进程打开
  4. 该请求立即返回 200,但对同一端点的第二个请求将需要前 3 个完成。

如果我在https://github.com/tiangolo/uwsgi-nginx-flask-docker上运行它:

...

  1. 请求等到 3 完成,然后返回 200

如果我使用python -m...运行该过程,它会按预期工作。

我的 uwsgi.ini 看起来像这样

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

您的 uwsgi.ini 应该启用默认情况下被阻止的线程。

将其更改为以下

[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