ZeeBlue
ZeeBlue

Reputation: 17

python process creation and process ID

Can some one suggest what could be the best method to spawn a child process in python? I have used one method like below.How can I get the pid of child process in below method ? Or how do I know the process been actually created ?

def main():
    process = QtCore.QProcess()
    process.start('python', ['./Hello_World.py'])
    time.sleep(5)
    process.kill()

Upvotes: 0

Views: 91

Answers (1)

foodtooth
foodtooth

Reputation: 146

How about using popen.

import subprocess

p = subprocess.Popen(['ls', '-alh'])

print(p.pid)

You can also use the instance to communicate with the spawned process.

Upvotes: 2

Related Questions