Pythonスクリプト:tmuxセッションの操作が完了するのを待ちます。

Pythonスクリプト:tmuxセッションの操作が完了するのを待ちます。

各実行は、独自のtmuxセッション内の他のPythonスクリプトの任意の引数を使用してPythonスクリプトを継続的に実行しようとします。私がやろうとしているタスクの非常に簡単な概要は次のとおりです。

# 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?

たとえば、乱数が57、61、88...などであるとします。上記のスクリプトは次のように実行する必要があります。

  • 「mysession57」というtmuxセッションの「myscript.py 57」
  • 「mysession61」というtmuxセッションの「myscript.py 61」
  • 「mysession88」というtmuxセッションの「myscript.py 88」...など。

しかし、スクリプトがtmuxセッション内のすべてのスクリプトが完了するのを待つことをどのように確認しますか?

ベストアンサー1

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

おすすめ記事