Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am making a python script, and from the python script I must launch multiple python scripts that must run all at one time. It would be preferred for the other scripts to run in the background and feed the input back to the main console. This must work on all major OSes. Also, it is critical to run them simotaneously, otherwise I would use defs. Running python 2.7.8, by the way.

Update: Sorry for title mismatch. Cookies glitched or something. I currently have a main script, which i need to run several more python scripts from all at once, and return the output live to the main window. If you can think of another way that is os-inspecific that can do that, let me know!

Update 2: I found a solution: var=subprocess.Popen(['python', 'file.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in favTL.stdout" print line

share|improve this question
    
Your description has nothing to do with the title. You can do this type of thing with subprocess and potentially the daemon module. But its more than a few lines of code. You need to give an example of what you've done and narrow your question to problems in that code. –  tdelaney Nov 13 '14 at 2:58

1 Answer 1

up vote 0 down vote accepted

Have you looked into the python thread module?

thread.start_new_thread(function, args[, kwargs])

will start a new thread in parallel. You can either import the other python files and call the specific functions you want, or run the whole script with

subprocess.call( ["python", "file.py"] )

...though making shell calls will be slightly less portable between OS's.

share|improve this answer
    
ill take a look! Does it allow also writing the results to the main terminal? –  Noah Overcash Nov 14 '14 at 14:56
    
Yup, a process and all of its sub-threads will all print to the same terminal. –  Mike Ounsworth Nov 14 '14 at 15:08
    
Great! I'll test it soon. Just to be sure, it works with Mac, Win, and Linux? –  Noah Overcash Nov 14 '14 at 15:12
    
Yup, the thread module is completely internal to python, so OS doesn't matter at all if you're only using thread. subprocess however is making system calls, so varies a little bit, for example subprocess.Popen(['python', 'folder\file.py'] on Windows, but subprocess.Popen(['python', 'folder/file.py'] (different slash) on Mac and *nix. –  Mike Ounsworth Nov 14 '14 at 15:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.