python - Signal handling in Pylons -
i have pylons project need update in-memory structures periodically. should done on-demand. decided come signal handler this. user sends sigusr1 main pylons thread , handled project.
this works except after handling signal, server crashes following exception:
file "/usr/lib/python2.6/socketserver.py", line 264, in handle_request fd_sets = select.select([self], [], [], timeout) select.error: (4, 'interrupted system call') is possible fix this?
tia.
yes, possible, not easy using stock python libraries. due python translating os errors exceptions. however, eintr should cause retry of system call used. whenever start using signals in python see error sporadically.
i have code fixes this (safesocket), forking python modules , adding functionality. needs added everywhere system calls used. it's possible, not easy. can use open-source code, may save years of work. ;-)
the basic pattern (implemented system call decorator):
# decorator make system call methods safe eintr def systemcall(meth): # have import way avoid circular import _socket import error socketerror def systemcallmeth(*args, **kwargs): while 1: try: rv = meth(*args, **kwargs) except environmenterror why: if why.args , why.args[0] == eintr: continue else: raise except socketerror why: if why.args , why.args[0] == eintr: continue else: raise else: break return rv return systemcallmeth you use around select call.
Comments
Post a Comment