D
D
Dmitry2018-05-30 12:38:01
Python
Dmitry, 2018-05-30 12:38:01

What happens in uWSGI with subprocess.Popen?

Can you please explain to me what is happening in my application running via uWSGI when I try to do subprocess.Popen?
There is one subtlety - I use gevent and in uWSGI I use the built-in ability to work with gevent.

from gevent.subprocess import Popen, PIPE
import sys

def my_view(request, *args, **kwargs):
        sub = Popen(sys.executable + ' my_worker.py args', stdout=PIPE, shell=True)
        out, err = sub.communicate()
        return out

When I run locally through the built-in Django test server, everything works.
When I run it through uWSGI, when I call the view in the uWSGI logs, I get an error:
unable to load configuration from my_worker.py

What is uWSGI trying to do? What other configuration is it trying to look for in my workflow that should just be done in a subprocess?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-05-30
@dimanjy

The problem was that when you run the application from uWSGI, sys.executablethe path lies not to the Python interpreter, but to the uwsgi-core binary.
Thanks to Pavel Denisov and sim3x for their help!

J
Jock Tanner, 2018-05-30
@Tanner

Being a hereditary telepath, I will assume that you make imports in the my_worker.py file that lead to the launch of the built-in flask web server. The idiomatic “if __name__ == '__main__':” is missing somewhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question