Python script: wait until job in tmux session has completed

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















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?










share|improve this question
























  • 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
    Feb 12 '15 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
    Feb 12 '15 at 2:52

















0















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?










share|improve this question
























  • 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
    Feb 12 '15 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
    Feb 12 '15 at 2:52













0












0








0


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?










share|improve this question
















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?







scripting python tmux






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 12 '15 at 2:10







geo909

















asked Feb 12 '15 at 2:00









geo909geo909

262211




262211












  • 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
    Feb 12 '15 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
    Feb 12 '15 at 2:52

















  • 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
    Feb 12 '15 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
    Feb 12 '15 at 2:52
















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
Feb 12 '15 at 2:49





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
Feb 12 '15 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
Feb 12 '15 at 2:52





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
Feb 12 '15 at 2:52










1 Answer
1






active

oldest

votes


















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





share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f184363%2fpython-script-wait-until-job-in-tmux-session-has-completed%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    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





    share|improve this answer





























      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





      share|improve this answer



























        0












        0








        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





        share|improve this answer















        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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 18 '15 at 3:40

























        answered Feb 17 '15 at 5:01









        youssef souraniyoussef sourani

        11




        11



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f184363%2fpython-script-wait-until-job-in-tmux-session-has-completed%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay