How to run several other python scripts together and send their arguments?

I need to run and run 24 independent python scripts on windows 7. I want one script to run them all at the same time ... without the right of everyone (I'm not Sauron) or waiting for their goals, I find os.startfile () interesting for this. But I was unable to send arguments with this 24.

matchoin1.py (one of 24 script to run)

import sys
print "hello:",sys.argv 

Anti_Sauron_script.py (one that will run all 24 together)

sys.argv=["send","those","arguments"] 
os.startfile("C:\\Users\\coincoin1.py")

How to send arguments to these scripts and run them together?

+5
source share
4 answers

(multiprocessing.Process) (multiprocessing.Queue), , . :

import multiprocessing

def processWorker(input, result):
    work = input.get()
    ## execute your command here
    pipe = subprocess.Popen(command, stdout = subprocess.PIPE,
                             stderr = subprocess.PIPE, shell = True)
    stdout, stderr = pipe.communicate()
    result.put(pipe.returncode)

input  = multiprocessing.Queue()
result = multiprocessing.Queue()

p = multiprocessing.Process(target = processWorker, args = (input, result))
p.start()
commandlist = ['ls -l /', 'ls -l /tmp/']
for command in commandlist:
    input.put(command)
for i in xrange(len(commandlist)):
    res = result.get(block = True)
    if not res is 0:
        print 'One command failed'

, , , workid (workid , ). .Queue , stdout/err, . , .

- , , get max, :

import Queue
try:
    res = result.get(block = True, timeout = 10)
except Queue.Empty:
    print error
+4

something like that?

from subprocess import Popen, PIPE

python_scripts = ['coincoin1.py','coincoin2.py','coincoin3.py'...]
args = ' -w hat -e ver'

procs = []
for f in python_scripts:
    procs.append(Popen(f+args, shell=True,stdout=PIPE,stderr=PIPE))

results = []

while procs:
    results.append (procs.pop(0).communicate())

do_something_with_results(resuls)
+1
source

Use the call function from the subprocess module (http://docs.python.org/library/subprocess.html#module-subprocess).

import subprocess
subprocess.call([path, arg1, arg2...])
-1
source

All Articles