2017-09-26 2 views
0

오늘 멀티 프로세싱에서 시작되었지만 물론 몇 가지 문제가 있습니다.두 번째 프로세스를 시작할 때 파이썬 다중 처리 오류가 발생했습니다.

나는 두 프로세스 생성 :

import multiprocessing as mp 

# twitter parser 
twitterProc = mp.Process (target=TwitterProcess) 
twitterProc.start() 

# rss parser 
RssProc = mp.Process (target=RssProcess) 
RssProc.start() 

코드 개시 RssProc 그것이 다른 1 ~ 2 초가 작동 주먹 프로세스 (twitterProc)를 시작하고 정상적으로 작동하고 제 프로세스를 시작 1-2 초후 그러한 오류 목록으로 중단되었습니다 :

Connected to pydev debugger (build 172.3757.67) 
Traceback (most recent call last): 
Error in atexit._run_exitfuncs: File "_pydevd_bundle/pydevd_cython.pyx", line 735, in _pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython.c:15637) 

Traceback (most recent call last): 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs 
func(*targs, **kargs) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/util.py", line 325, in _exit_function 
p.join() 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 145, in join 
self.do_wait_suspend(thread, frame, event, arg) 
File "_pydevd_bundle/pydevd_cython.pyx", line 252, in _pydevd_bundle.pydevd_cython.PyDBFrame.do_wait_suspend (_pydevd_bundle/pydevd_cython.c:5643) 
self._args[0].do_wait_suspend(*args, **kwargs) 
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 767, in do_wait_suspend 
res = self._popen.wait(timeout) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/forking.py", line 154, in wait 
return self.poll(0) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/forking.py", line 135, in poll pid, sts = os.waitpid(self.pid, flag) 
KeyboardInterrupt 
time.sleep(0.01) 
KeyboardInterrupt 
Process Process-RSS: 
Traceback (most recent call last): 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap 
Error in sys.exitfunc: 
Traceback (most recent call last): 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs 
func(*targs, **kargs) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/util.py", line 325, in _exit_function 
self.run() 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 114, in run 
p.join() 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 145, in join 
self._target(*self._args, **self._kwargs) 
File "/Users/Stas/PycharmProjects/untitled/streambot.py", line 674, in __init__ 
res = self._popen.wait(timeout) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/forking.py", line 154, in wait 
return self.poll(0) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/forking.py", line 135, in poll 
pid, sts = os.waitpid(self.pid, flag) 
KeyboardInterrupt 
for source in config.feedList: 
File "/Users/Stas/PycharmProjects/untitled/streambot.py", line 674, in __init__ 
for source in config.feedList: 
File "_pydevd_bundle/pydevd_cython.pyx", line 970, in _pydevd_bundle.pydevd_cython.SafeCallWrapper.__call__ (_pydevd_bundle/pydevd_cython.c:19428) 
ret = (<object>method_obj)(*args) 
File "_pydevd_bundle/pydevd_cython.pyx", line 501, in _pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython.c:18762) 
cpdef trace_dispatch(self, frame, str event, arg): 
File "_pydevd_bundle/pydevd_cython.pyx", line 744, in _pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython.c:15791) 
raise 
File "_pydevd_bundle/pydevd_cython.pyx", line 735, in _pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython.c:15637) 
self.do_wait_suspend(thread, frame, event, arg) 
File "_pydevd_bundle/pydevd_cython.pyx", line 252, in _pydevd_bundle.pydevd_cython.PyDBFrame.do_wait_suspend (_pydevd_bundle/pydevd_cython.c:5643) 
self._args[0].do_wait_suspend(*args, **kwargs) 
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 767, in do_wait_suspend 
time.sleep(0.01) 
KeyboardInterrupt 

Process finished with exit code 0 

무엇이며 어떻게 해결합니까?

답변

0

나는 프로세스를 만든 후에 join 메서드를 사용하는 것이 가장 좋은 방법이라고 생각합니다. 프로세스가 스크립트의 마지막에 작업

twitterProc.join()RssProc.join()의 완료 될 때까지 기다려야 정보 용을 메인 스레드에 가입

관련 문제