I have a pylons project where I need to update some in-memory structures periodically. This should be done on-demand. I decided to come up with a signal handler for this. User sends SIGUSR1 to the main pylons thread and it is handled by the project.
This works except after handling the signal, the server crashes with 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 it possible to fix this?
TIA.
Yes, it is possible, but not easy using the stock Python libraries. This is due to Python translating all OS errors to exceptions. However, EINTR should really cause a retry of the system call used. Whenever you start using signals in Python you will see this error sporadically.
I have code that fixes this (SafeSocket), by forking Python modules and adding that functionality. But it needs to be added everywhere system calls are used. So it’s possible, but not easy. But you can use my open-source code, it may save you years of work. 😉
The basic pattern is this (implemented as a system call decorator):
You could also just use that around your select call.