Opening a process with Popen and getting the PID

前端 未结 1 624
旧时难觅i
旧时难觅i 2020-11-30 01:40

I\'m working on a nifty little function:

def startProcess(name, path):
    \"\"\"
    Starts a process in the background and writes a PID file

    returns i         


        
相关标签:
1条回答
  • 2020-11-30 02:20

    From the documentation at http://docs.python.org/library/subprocess.html:

    Popen.pid The process ID of the child process.

    Note that if you set the shell argument to True, this is the process ID of the spawned shell.

    If shell is false, it should behave as you expect, I think.

    If you were relying on shell being True for resolving executable paths using the PATH environment variable, you can accomplish the same thing using shutil.which instead, then pass the absolute path to Popen instead. (As an aside, if you are using Python 3.5 or newer, you should be using subprocess.run rather than Popen.

    0 讨论(0)
提交回复
热议问题