import multiprocessing as mp import os def worker(num, input_queue): """thread worker function""" print 'Worker:', num for inp in iter(input_queue.get, 'stop'): print 'executing %s' % inp os.popen('./mmul.x < '+inp+' >'+inp+'.out' ) return if __name__ == '__main__': # # build the queue input_queue = mp.Queue() # for i in range(4): input_queue.put('in'+str(i)) # the queue contains the name of the inputs for i in range(4): input_queue.put('stop') # add a poison pill for each consumer for i in range(4): p = mp.Process(target=worker, args=(i, input_queue)) p.start()