I get the following error when using the multiprocessing module in a python daemon process (using python-daemon ):
Traceback (most recent call last):
File "/usr/local/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func (* targs, ** kargs)
File "/usr/local/lib/python2.6/multiprocessing/util.py", line 262, in _exit_function
for p in active_children ():
File "/usr/local/lib/python2.6/multiprocessing/process.py", line 43, in active_children
_cleanup ()
File "/usr/local/lib/python2.6/multiprocessing/process.py", line 53, in _cleanup
if p._popen.poll () is not None:
File "/usr/local/lib/python2.6/multiprocessing/forking.py", line 106, in poll
pid, sts = os.waitpid (self.pid, flag)
OSError: [Errno 10] No child processes
The daemon (parent) process spawns a series of processes (children), and then periodically checks the processes to see if they are complete. If the parent discovers that one of the processes has completed, it then tries to restart the process. It is at this moment that the foregoing is excluded. It seems that as soon as one of the processes is completed, any operation associated with the multiprocessing module will throw this exception. If I run identical code in a non-daemon python script, it runs without any errors.
EDIT:
Script example
from daemon import runner
class DaemonApp(object):
def __init__(self, pidfile_path, run):
self.pidfile_path = pidfile_path
self.run = run
self.stdin_path = '/dev/null'
self.stdout_path = '/dev/tty'
self.stderr_path = '/dev/tty'
def run():
import multiprocessing as processing
import time
import os
import sys
import signal
def func():
print 'pid: ', os.getpid()
for i in range(5):
print i
time.sleep(1)
process = processing.Process(target=func)
process.start()
while True:
print 'checking process'
if not process.is_alive():
print 'process dead'
process = processing.Process(target=func)
process.start()
time.sleep(1)
app = DaemonApp('/root/bugtest.pid', run)
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()
source
share