0
スーパーバイザーを使用してこのようなスクリプトを実行します。スーパーバイザが停止または中断すると、私は正常にスクリプトを終了しようとします。これは私の現在のコードPythonプロセスプールエグゼキュータがシグナルをシャットダウンする
import concurrent.futures
import random
import os
import signal
import sys
executor = concurrent.futures.ProcessPoolExecutor(max_workers=2)
some_flag = True
def some_func():
while some_flag:
executor.submit(print_some_num)
def print_some_num():
print("From worker :{}".format(os.getpid()))
print(random.randint(0,10))
def handler(arg1, arg2):
print("Got interrupt")
some_flag = False
sys.exit("Run for ur life")
#executor.shutdown(wait = False) ----> not working
print("Shutdown")
signal.signal(signal.SIGTERM,handler)
signal.signal(signal.SIGINT,handler)
if __name__ == '__main__':
some_func()
でこれが正常に動作し、私はexecutor.shutdown(真/偽=待つ)について読んだとき、今私は混乱しています。だから私はそれを試み、私はシャットダウンにexecutorを得ることができませんでした(それはちょうどハングする)。これらの質問
1) what does executor.shutdown do that sys.exit() doesn't do.
2) What is advisable in production environment? If executor shutdown is required, please help me fix the issue with shutdown.
あなたのコメントを追加してください。 – Anandan