First calling Popen
with shell=False
doesn't mean that the underlying python won't try to open a window/console. It's just that the current python instance executes python.exe
directly and not in a system shell (cmd or sh).
Second, Popen
returns a handle on the process, and you have to perform a wait()
on this handle for it to end properly or you could generate a defunct process (depending on the platform you're running on). I suggest that you try
p = subprocess.Popen(["python.exe", "a.py"], shell=False)
return_code = p.wait()
to wait for process termination and get return code.
Note that Popen
is a very bad way to run processes in background. The best way would be to use a separate thread
import subprocess
import threading
def run_it():
subprocess.call(["python.exe", "a.py"], shell=False)
t = threading.Thread(target=run_it)
t.start()
# do your stuff
# in the end
t.join()