자신의 daemonzing 모듈을 포함 보인다. 코드 개선을위한 제안에 감사드립니다.
def start_server():
pyrodaemon = Pyro.core.Daemon()
#setup daemon and nameserver
#Don't want to close the pyro socket
#Need to remove SIGTERM map so Processing doesn't kill the subprocess
#Need to explicitly detach for some reason I don't understand
with daemon.DaemonContext(files_preserve=[pyrodaemon.sock],signal_map={signal.SIGTERM:None},detach_process=True):
while running:
pyrodaemon.handleRequests(timeout=1.0)
#when finished, clean up
pyrodaemon.shutdown()
def main():
p = Process(target=start_server)
p.daemon=True # Need to inform Process that this should run as a daemon
p.start()
time.sleep(3.0) # Important when running this program stand alone: Must wait long enough for start_server to get into the daemon context before the main program exits or Process will take down the subprocess before it detaches
do_other_stuff_not_in_the_daemon()
답장을 보내 주셔서 감사합니다. 최근에 저 해결책을 가로 질러 왔 더라면, 나는 동의한다. 그러나 python-daemon은 프로그램이 데몬으로 시작하여 반환하지 않는 하나의 기능을 갖는보다 표준적인 패러다임을 목표로합니다. daemon.DaemonContext()와 : 나는의 라인을 따라 뭔가를하고 싶은 some_daemon_loop()를 continue_with_this_function_after_daemon_has_launched() 나는 어떤 제안을 주셔서 감사합니다 . – glenn
전에 pyro를 보지 못했습니다. 그들의 코드를 간단하게 살펴보면, "데몬"클래스는 스레드 디스패처와 같은 것으로 별도의 프로세스가 아닙니다. 코드에서 어디에서 포크를 실행하든 상관 없습니다. Pyro에는 데몬 리얼 데몬 기능을위한 모듈이 포함되어 있습니다. – JimB