これで、時宜にかなった方法で実行されるかどうかを判断するツールを呼び出す方法があります。サーバーにハートビートを送って、まだ実行中であることを伝え、時間がなくなったかどうかを確認できます。ハートビートを送信中にメソッドを実行し、メソッドの戻り値を取得する方法
class Worker:
def run:
proc = Process(target=_execute, args=(foo, bar,))
proc.start()
while True:
if proc.is_alive():
if not _heart_beat():
# Server told us to stop, kill the _execute process.
proc.terminate()
break
else:
# _execute is done, we can stop sending heartbeats
break
time.sleep(beat_interval)
def _execute(foo, bar):
#exec /bin/foo
#exec /bin/bar
#do something with their output
return foo_bar
これは私のために動作しますが、私は_execute
の戻り値を取得できるようにしたいと思います:
のコードは次のようになります。