1

I am trying to continuously run a python script with random parameters from another python script, where each run is in its own tmux session. A very simplified overview of what I'm trying to do goes like this:

# Python script to run other python scripts from subprocess import call import random while True param = randint(1,100) runmyscript ="tmux send-keys -t mysession"+str(param)+" 'python myscript.py param' " call(runmyscript) #Wait until myscript.py is done running in its tmux session <-- How to do that? 

For example, let's say that the random numbers are 57, 61, 88 ... etc. The above script should run:

  • 'myscript.py 57' in a tmux session called "mysession57"
  • 'myscript.py 61' in a tmux session called "mysession61"
  • 'myscript.py 88' in a tmux session called "mysession88" ... etc

But how can I make sure that the script waits until each script in its tmux session is finished?

3
  • Not an answer, and I don't know tmux but... there must be a better way, a more programmatic way, of doing what you need to do than simulating keypresses in a command window to run a script (because that's what I assume tmux send-keys does). Anything that remotely resembles directly invoking some kind of command instead of simulating keypresses would have a better chance of providing you with a method of notifying the caller when it's done.
    – Celada
    CommentedFeb 12, 2015 at 2:49
  • You're 100% right. But I have reached the point that I must run what I have and get my results asap. That said, I'm sure that the question could be rephrased so that it refers to the same concept but less sloppy..
    – geo909
    CommentedFeb 12, 2015 at 2:52
  • Are you using tmux for parallelization? Don't. Try this: stackoverflow.com/questions/7207309/…
    – TZubiri
    CommentedMar 14, 2020 at 4:06

1 Answer 1

0
from subprocess import call import random while True: param = random.randint(1,100) #add random first or from random import randint runmyscript ="tmux send-keys -t mysession %s 'python myscript.py param' "%str(parma) call(runmyscript,shell=True)#you should add if or something to break loop 

    You must log in to answer this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.