I'm trying to use subprocessing in Python, but I don't understand if it can be used with a function, because in the official Python documentation, the syntax of subprocess.Popen takes arguments, but I don't see anything that can be related to a function. Or is there another way to spawn a new process dedicated to a function without subprocess ?
3 Answers
What you need is multiprocessing not subprocessing
http://docs.python.org/library/multiprocessing.html#the-process-class
from multiprocessing import Process
def my_function(name):
print "My name is %s" % name
if __name__ == '__main__':
p = Process(target=my_function, args=('Yarkee', ))
p.start()
p.join() # this blocks until the process terminates
1 Comment
Pollux
I tried multiprocessing, but it always conflicts with tkinter (used for the GUI).