python - Why does Popen hang when used in Django view? -
In one of my Django's views, I need to start an asynchronous task that seems to end in minutes Could. Since the celery + message queue would be an overkill for this task, I used the subprocess. Papen is used to create a sub-process like this:
args = ['python', SCRIPT_PATH, "& amp;"]; Try: Subprances Popen (Algs, Stdaut = Sbproses Kpeepii, Stederr = Sbproses. Piipii) except # sync calls to return Actiteepiarpispakshn ( "Job Submit")
I NGN + run my Dijengo app When I start the server and leave the session open, the code above works fine. But when I close the shell session, the code stops and the pop is hanging in line.
I think it's about stdout / stderr arguments, but I do not know how to make it work to change it.
========= Edit ===========
I do this in the script: I used Selenium WebDriver + To load a Web page and submit a form, in this process, selenium or phatcoms write for standard output or standard error. When I start the guntoon in a conch, and later shut the shell session, the writing of selenium or phantom fails. When I start the Gnorornon with its output, it redirects to a file like this:
gunicorn app.wsgi & gt; /tmp/gunicorn.log & amp;
The problem has gone
Although I gave you With the details popin line can not be detected due to blocking, then I have an alternative suggestion, besides, I'm not sure that you are also referred to as "& amp; option.
You can get stdout and stderr Error streams can use NamedTemporaryFiles
Tempfile Import from NamedTemporaryFile Output = NamedTemporaryFile (delete = False) Error = NamedTemporaryFile Delete = false Popen (args, stdout = output, stderr = It does not block I believe that you have already taken precautions what should be done when Popen is over. Near Popen Docks The warning about pipes objects is that I am pasting it here for completion
The data to be read is in the memory of the buffer, so do not use this method if the size of the data is large or unlimited .
Comments
Post a Comment