0
관리자처럼이 스크립트를 실행합니다. 그래서 수퍼바이저가 중단되거나 인터럽트되면 스크립트에서 정상적으로 벗어나려고합니다. 이것은 내 현재 코드파이썬 프로세스 풀 Executor shutdown on signal
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를 shutdown (단지 멈춘다) 할 수 없었다. 이 질문들로 나를 도와주세요.
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