D
dzizes451
Hello!
I wrote a python (2.6) deamon running on linux. Program (deamon,
manager) collects lets say work-orders from db and creates sub-
processes for each one. Sub-processes do their job with out problems,
errors, exceptions. However, sometimes deamon throws:
Traceback (most recent call last):
File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.6/multiprocessing/util.py", line 281, in
_exit_function
p.join()
File "/usr/lib/python2.6/multiprocessing/process.py", line 119, in
join
res = self._popen.wait(timeout)
File "/usr/lib/python2.6/multiprocessing/forking.py", line 117, in
wait
return self.poll(0)
File "/usr/lib/python2.6/multiprocessing/forking.py", line 106, in
poll
pid, sts = os.waitpid(self.pid, flag)
OSError: [Errno 4] Interrupted system call
the main deamon process crushes (after some time) and the sub-
processes (childs) work fine until their work is finished.
below sample code that is responsible for creating sub_processes :
#!/usr/bin/python2.6
import pwd
import os
import sys
import time
import multiprocessing
import signal
import traceback
from deamon import deamon
from post import post
class manager(deamon):
def __run_subprocess(self, typ, work_order):
def runrun(t, z):
self.__info('creating object post for %s' %(z))
wns = post(z)
self.__info('done creating object post for %s' %(z))
#slownik z choiceem opcji
choice = {'typ1': wns.typ1,
'typ2': wns.typ2,
'typ3': wns.typ3}
if typ in choice:
self.__info('lounching %s for %s' %(t, z))
choice[typ]()
else:
self.__blad('nie znam %s typu operacji post, znam
tylko %s' \
%(t, str(choice)))
wns.endit()
del(wns)
self.__blad('problem with starting proces for =%s, typ=
%s' %(z, t))
try:
p = multiprocessing.Process(target=runrun,
args=(typ,work_order))
self.__info('done preparing proces...')
p.start()
self.__info('done lounching process...doing join...')
p.join()
return p.pid
except Exception, err:
ex = sys.exc_info()
sys.stderr.write(str(sys.exc_info()))
msg = 'manager.__run_subprocess %s error in line %s'
sys.stderr.write(msg %(str(err), ex[2].tb_lineno))
#traceback.print_last()
return None
def __liczba_wierszy(self, active_child):
return int(self._deamon__liczba_proces - active_child)
def run(self):
try:
while True:
active_child = len(multiprocessing.active_children())
#czy liczba pod-procesow <= liczba mozliwych pod-
procesow
if active_child <= self._deamon__liczba_proces:
lista_zlecen = self._deamon__baza.get_work(
self.__liczba_wierszy(active_child))
if len(lista_zlecen) > 0:
for work_order in lista_zlecen:
self.__info('start %s' %(work_order))
pid =
self.__run_subprocess('typ1',work_order)
self.__info('end %s %s' %(work_order,
str(pid)))
time.sleep(self._deamon__sleep)
elif active_child == self.__liczba_proces:
msg = 'number of processes %i is equal to maximum
%i, '\
'going sleep for %i seconds' %(
active_child,
self.__liczba_proces, self._deamon__sleep)
self.__info(msg)
time.sleep(self._deamon__sleep)
else:
self.__info('nothing to do... going sleep for %i
seconds'
%(self._deamon__liczba_proces))
#self._deamon__baza.zamknij_polacznie()
time.sleep(self._deamon__sleep)
except Exception, err:
ei = sys.exc_info()
msg = 'manager.run %s\n' %(str(err))
sys.stderr.write('error in line %s\n' %
(str(ei[2].tb_lineno)))
sys.stderr.write(msg)
def receive_sygnal(self, signum, stack):
if signum == 10:
#print 'otrzymalem sygnal', signum
self.__zapisz_status()
elif signum == 12:
self.__info('cheking if there are any active sub-
processes')
while len(multiprocessing.active_children()) > 0:
self.__info('liczba podprocesow > 0, ide spac na 10
sekund')
time.sleep(10)
else:
print 'got unknown signal', signum
I wrote a python (2.6) deamon running on linux. Program (deamon,
manager) collects lets say work-orders from db and creates sub-
processes for each one. Sub-processes do their job with out problems,
errors, exceptions. However, sometimes deamon throws:
Traceback (most recent call last):
File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.6/multiprocessing/util.py", line 281, in
_exit_function
p.join()
File "/usr/lib/python2.6/multiprocessing/process.py", line 119, in
join
res = self._popen.wait(timeout)
File "/usr/lib/python2.6/multiprocessing/forking.py", line 117, in
wait
return self.poll(0)
File "/usr/lib/python2.6/multiprocessing/forking.py", line 106, in
poll
pid, sts = os.waitpid(self.pid, flag)
OSError: [Errno 4] Interrupted system call
the main deamon process crushes (after some time) and the sub-
processes (childs) work fine until their work is finished.
below sample code that is responsible for creating sub_processes :
#!/usr/bin/python2.6
import pwd
import os
import sys
import time
import multiprocessing
import signal
import traceback
from deamon import deamon
from post import post
class manager(deamon):
def __run_subprocess(self, typ, work_order):
def runrun(t, z):
self.__info('creating object post for %s' %(z))
wns = post(z)
self.__info('done creating object post for %s' %(z))
#slownik z choiceem opcji
choice = {'typ1': wns.typ1,
'typ2': wns.typ2,
'typ3': wns.typ3}
if typ in choice:
self.__info('lounching %s for %s' %(t, z))
choice[typ]()
else:
self.__blad('nie znam %s typu operacji post, znam
tylko %s' \
%(t, str(choice)))
wns.endit()
del(wns)
self.__blad('problem with starting proces for =%s, typ=
%s' %(z, t))
try:
p = multiprocessing.Process(target=runrun,
args=(typ,work_order))
self.__info('done preparing proces...')
p.start()
self.__info('done lounching process...doing join...')
p.join()
return p.pid
except Exception, err:
ex = sys.exc_info()
sys.stderr.write(str(sys.exc_info()))
msg = 'manager.__run_subprocess %s error in line %s'
sys.stderr.write(msg %(str(err), ex[2].tb_lineno))
#traceback.print_last()
return None
def __liczba_wierszy(self, active_child):
return int(self._deamon__liczba_proces - active_child)
def run(self):
try:
while True:
active_child = len(multiprocessing.active_children())
#czy liczba pod-procesow <= liczba mozliwych pod-
procesow
if active_child <= self._deamon__liczba_proces:
lista_zlecen = self._deamon__baza.get_work(
self.__liczba_wierszy(active_child))
if len(lista_zlecen) > 0:
for work_order in lista_zlecen:
self.__info('start %s' %(work_order))
pid =
self.__run_subprocess('typ1',work_order)
self.__info('end %s %s' %(work_order,
str(pid)))
time.sleep(self._deamon__sleep)
elif active_child == self.__liczba_proces:
msg = 'number of processes %i is equal to maximum
%i, '\
'going sleep for %i seconds' %(
active_child,
self.__liczba_proces, self._deamon__sleep)
self.__info(msg)
time.sleep(self._deamon__sleep)
else:
self.__info('nothing to do... going sleep for %i
seconds'
%(self._deamon__liczba_proces))
#self._deamon__baza.zamknij_polacznie()
time.sleep(self._deamon__sleep)
except Exception, err:
ei = sys.exc_info()
msg = 'manager.run %s\n' %(str(err))
sys.stderr.write('error in line %s\n' %
(str(ei[2].tb_lineno)))
sys.stderr.write(msg)
def receive_sygnal(self, signum, stack):
if signum == 10:
#print 'otrzymalem sygnal', signum
self.__zapisz_status()
elif signum == 12:
self.__info('cheking if there are any active sub-
processes')
while len(multiprocessing.active_children()) > 0:
self.__info('liczba podprocesow > 0, ide spac na 10
sekund')
time.sleep(10)
else:
print 'got unknown signal', signum