python - Unable to kill Flask server launched by Popen on Ubuntu -


What I'm trying to achieve is the lesser requirement. # run PYE import requests import time from subprocess import Popen, PIPE server = popon ("./exp.py", stdout = PIPE, stderr = PIPE, shell = True) Time.sleep (1) res = requests.get ("http: // localhost: 1234 /") res.status_code == 200 server.kill () server.terminate () res = requests.get ("http: // Localhost: 1234 / ") Print

and the actual server script. < On order (): see DEF (): make_response ("") return if __name__ == "__main__": app.run (host = "localhost", port = 1234) line i python run.py Run From Shell:

  (t) Khushon @ Fubini: / tmp $ ps aux | Grep app Khushan 21452 0.6 0.4 16416 9992 points / 2s 03:50 0:00 dragon ./app.py Yeukhon 21471 0.0 0.0 4384 804 points / 2s + 03:51 0:00 grep --color = auto app   

is still hanging there. I have to hit it with the command line In fact, the last line of run.py Tells that the server was still alive (200 was returned)

I tried to kill with os.kill (server) .pid, signal.SIGTERM) and os.kill (server.pid, signal.SIGKILL) < / Code> but none works

Normally kill will work, but I do not really know why it can not get the signal. I'm sure somehow refuses to shut down the flask.

What options do I have?

Strangely, my script works perfectly well on Mac OSX (I'm on 10.8.5, Mountain Lion). So far, I have tested on two Ubuntu 12.04 machines and they have the same behavior. I'm running Python 2.7.3 on my Mac OSX and Python 2.7.2 on both Mac OSX.

Correction : I have only one option to use. But I do not want to and yes, I have to launch one using Popen.

shell = true , the command is run by subshell.

  server = popon ("./exp.py", stdout = PIPE, stderr = PIPE, shell = true)   

server Terminate will kill subsealand, but the web server will not be killed.


How to verify this? Try print server.pid after the PP call, and compare it with ps output.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -