简体   繁体   中英

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 . As the called modules are pure python my idea is to run it with multiprocessing.Process or Pull . The request is processed like this:

  1. A request arrives at a Connexion endpoint
  2. Some preprocessing is done
  3. The function is opened with Popen
  4. The request returns a 200 without waiting for 3. to finish

When replacing:

Popen(...)

with

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

this happens to multiprocessing with uwsgi:

  1. A request arrives at a Connexion endpoint
  2. Some preprocessing is done
  3. The function is opened with Process
  4. The request returns a 200 immediately, but a second request to the same endpoint will require the previous 3 to finish.

in if I run it on https://github.com/tiangolo/uwsgi-nginx-flask-docker :

...

  1. The request waits until 3 is finished and then returns a 200

It works as espected if I run the process with python -m... .

My uwsgi.ini looks like this

 [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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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