Python runs a system command and then exits ... will not exit

I have the following python code:

os.system("C:/Python27/python.exe C:/GUI/TestGUI.py") sys.exit(0) 

He perfectly executes the command and a window appears. However, it does not exit the first script. He just stays there, and I ultimately have to get the process killed. Errors do not occur. What's happening?

+7
source share
4 answers

use subprocess.Popen instead of os.system

the command is executed and does not wait for it, and then exits:

 import subprocess import sys subprocess.Popen(["mupdf", "/home/dan/Desktop/Sieve-JFP.pdf"]) sys.exit(0) 

note that os.system(command) like:

 p = subprocess.Popen(command) p.wait() 
+10
source
 import sys ,subprocess subprocess.Popen(["C:/Python27/python.exe", "C:/GUI/TestGUI.py"]) sys.exit(0) 

Change from the subprocess module what you are looking for.

0
source

I suggest using os._exit instead of sys.exit , since sys.exit does not exit the program, but raises the exception level or exits the stream. os._exit(-1) terminates the entire program

0
source

KeyboardInterrupts and signals are visible only by the process (i.e. the main thread). If your nested command freezes due to some file reading or writing to a block, you will not be able to exit the program using any keyboard commands.

Why is read-only access to a named pipe open?

If you cannot eliminate the source of the disk block, one way is to wrap the process in a thread so that you can make it kill. But if you do, you will leave the opportunity for files with half written and damaged on the disk.

0
source

All Articles