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
-
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– tdelaney2014年11月13日 02:58:06 +00:00Commented Nov 13, 2014 at 2:58
1 Answer 1
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.
4 Comments
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.