2016-11-20 6 views
0

주 스레드를 종료하는 다중 처리를 사용하여 데몬 프로세스를 시작하려고합니다. 이 코드를 작성했습니다 :다중 처리를 사용하여 파이썬에서 데몬을 시작하는 방법

import multiprocessing as mp 
from time import sleep 

def mytarget(): 
    while True: 
     print "yes" 
     sleep(1) 

process = mp.Process(target=mytarget) 
process.daemon = True 
process.start() 

그러나 데몬 프로세스가 나타나지 않습니다.

import os 
from time import sleep 

def mytarget(): 
    while True: 
     print "yes" 
     sleep(1) 

pid = os.fork() 
if pid == 0: 
    mytarget() 

을하지만 윈도우에서 지원되지 않는 : 나는 그것을 이런 식으로 os.fork 사용하여 해결할 수 있습니다 알고 있습니다. 그래서 다중 처리 모듈을위한 솔루션이 필요합니다. 감사!

+0

다중 처리 모듈은이를위한 것이 아닙니다. 데몬이나 서비스를 만들려면 라이브러리를 사용하십시오. ['service' 패키지] (http://python-service.readthedocs.io/en/latest/)를 추천 할 수 있습니다. – MisterMiyagi

답변