Yes, itβs possible, but itβs not easy to use the Python stock libraries. This is because Python translates all OS errors into exceptions. However, the EINTR does indeed have to cause a reuse of the used system call. Whenever you start using signals in Python, you will see this error sporadically.
I have code that fixes this (SafeSocket) by formatting Python modules and adding this functionality. But it should be added wherever system calls are used. So itβs possible, but not easy. But you can use my open source code, it can save you many years .; -)
The main template is this (implemented as a system call decorator):
# decorator to make system call methods safe from EINTR def systemcall(meth): # have to import this way to avoid a circular import from _socket import error as SocketError def systemcallmeth(*args, **kwargs): while 1: try: rv = meth(*args, **kwargs) except EnvironmentError as why: if why.args and why.args[0] == EINTR: continue else: raise except SocketError as why: if why.args and why.args[0] == EINTR: continue else: raise else: break return rv return systemcallmeth
You can also just use this around your chosen call.
Keith source share