5

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 ?

1
  • Do you really need subprocess? What about threads? Commented Apr 27, 2013 at 13:10

3 Answers 3

5

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
Sign up to request clarification or add additional context in comments.

1 Comment

I tried multiprocessing, but it always conflicts with tkinter (used for the GUI).
3

Take a look at the multiprocessing module. This may have what you're looking for

Comments

2

The python subprocess module can be used to call external programs like this:

import subprocess
subprocess.call(["ls", "-l"])

While multiprocessing, as mentioned by @Yarkee, is bound to a function so its probably what you are looking for.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.