ã¿ã¤ããã®ã§ã½ã¼ã¹ã³ã¼ããèªãã§ã¿ãããããªãåèã«ãªã£ãã
51è¡ç®
resourceã¢ã¸ã¥ã¼ã«ã使ã£ã¦ããã®ãè¦ãã®ã¯ã¯ããã¦ã ã
for fd in range(resource.getrlimit(resource.RLIMIT_NOFILE)[0]): try: os.close(fd) except OSError: pass
57è¡ç®
dupããã¨æªä½¿ç¨ã®ä¸ã§æå°ã®ãã£ã¹ã¯ãªãã¿ã«å²ãå½ã¦ãããã®ãã
os.open(devnull, os.O_RDWR) os.dup(0) os.dup(0)
85è¡ç®
signal.signal(signal.SIGTERM, partial(sigterm, pid))
é¨åé¢æ°ä½¿ã£ã¦ãããããã¥ã¡ã³ãã«ããã¨signal.signalã®ç¬¬äºå¼æ°ã¯
handler ã¯äºã¤ã®å¼æ°ã¨ã¨ãã«å¼ã³åºããã¾ã: ã·ã°ãã«çªå·ãããã³ç¾å¨ã®ã¹ã¿ãã¯ãã¬ã¼ã (None ã¾ãã¯ãã¬ã¼ã ãªãã¸ã§ã¯ã
ã§ãé¨åé¢æ°ã«ãªã£ã¦ããsigtermã¯ä»¥ä¸ã®ããã«3å¼æ°ãåãåãé¢æ°ã第ä¸å¼æ°ã¯ããã¯ãã¡ã¤ã«åã
def sigterm(pid, signum, frame): logging.info("Caught signal %d. Stopping daemon." % signum) os.remove(pid) sys.exit(0)