开发者

How to run a code with different set of parameters without waiting for a code to execute with one parameter and then entering the next one

My python program takes two input parameters from the command line for execution eg (maxt, 30days). The execution time of this program is approximately 10 mins开发者_JS百科. I want to run the program three time ie first with maxt and 30 days, second with maxt and 14 days and third with maxt and 7 days. How could run the code three time without waiting for the code to execute with one set of parameter and then manually entering the second set of parameter and so on.... I do not want to loop my code internally.... Is there a way in which I can run the code with one set of parameter first then ask the system to wait for 10 mins and then run the same code with another set of parameters.... Any help is appreciated..... Thanking you


If you are on a unix command line:

$ yourprogram maxt 30days &
$ yourprogram maxt 14days &
$ yourprogram maxt 7days &

this starts your programs in the background in parallell.


It sounds like what you want is a shell script, like so:

#! /bin/sh

yourprogram maxt 30days
yourprogram maxt 14days
yourprogram maxt 7days

Put that in a file, chmod +x it, and run it as ./filename. It will have the same effect as typing those three commands, in sequence, at the command prompt, waiting for each one to finish before starting the next.


Here is an overly complicated bash one liner:

for days in 30 14 7 ; do yourprogram maxt ${days}days > output_$days & ; done

It writes out the output to separate files since it's possible it might get jumbled up otherwise.

If you want to do it inside python you can try the multiprocessing module: http://docs.python.org/library/multiprocessing.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜