プロセスの同期に関連する次の問題があります。
Python スクリプト startup.py、実行可能なマエストロ、および実行可能なティーがあります。私のpythonスクリプトstartup.pyはmaestroプログラムを開始し、teeを使用してmaestroのstderr/stdoutをログファイルにパイプし、コンソールに書き込みます。
次のコードを使用してこれを達成しました。
cmd = "maestro"
mae_err_log = "output.txt"
maestro = subprocess.Popen(cmd, stderr = subprocess.STDOUT, stdout=subprocess.PIPE)
tee = subprocess.Popen(['tee', mae_err_log], stdin = maestro.stdout)
maestro.stdout.close()
tee.communicate()
maestro_status = maestro.returncode
sys.exit(maestro_status)
私のマエストロ プログラムは、マエストロ プログラムを終了するときの gui プログラムです。内部的に posix system("maestro_cleanup &") api を呼び出し、すぐに終了します。バックグラウンドで maestro_cleanup を実行しているにもかかわらず、maestro_cleanup プログラムが終了するまで maestro プログラムがコンソールを解放しないことに気付きました。時間がかかるため、バックグラウンドで maestro_cleanup を実行する必要があり、maestro_cleanup が完了するまでコンソールを保持したくありません。上記のコードを使用すると、maestro_cleanup が終了するまで maestro プログラムは終了しません。
「ps -elf」は次のように表示されます。
0 S j 16876 6678 0 75 0 - 65307 wait 18:56 pts/53 00:00:00 python startup.py
0 Z j 17230 16876 4 76 0 - 0 exit 18:56 pts/53 00:00:04 [maestro] <defunct>
0 S j 17231 16876 0 77 0 - 948 pipe_w 18:56 pts/53 00:00:00 /usr/bin/tee output.txt
0 S j 17424 1 0 77 0 - 948 - 18:57 pts/53 00:00:00 maestro_cleanup
バックグラウンドでシステム API を使用して maestro_cleanup を開始したため、maestro_cleanup 親プロセスが maestro ではなくセッション プロセス ID であることがわかります。
maestro_cleanup が終了するまで maestro が終了しない理由は何ですか?
どんな助けでも大歓迎です。
-ビピン