@decorator
def interruptable(func, *args, **opts):
 while True:
  try:
   result = func(*args, **opts)
  except IOError as e:
   if (e.errno == errno.EINTR):
    continue
   raise e
  except OSError as e:
   if (e.errno in (errno.EINTR, errno.EINVAL)):
    continue
   raise e
  else:
   break
 return result

@ decorator def interruptable ( func , * args , ** opts ) : while True : try : result = func ( * args , ** opts ) except IOError as e : if ( e . errno == errno . EINTR ) : continue raise e except OSError as e : if ( e . errno in ( errno . EINTR , errno . EINVAL ) ) : continue raise e else : break return result
handle interruptable system calls osx and others are known to interrupt system calls URL URL#worse_is_better the @interruptable decorator handles this situation .