module documentation

Utility functions wrapping other functions.

Function CloseFdNoError Close a file descriptor ignoring errors.
Function GetClosedTempfile Creates a temporary file and returns its path.
Function IgnoreProcessNotFound Ignores ESRCH when calling a process-related function.
Function IgnoreSignals Tries to call a function ignoring failures due to EINTR.
Function IsExecutable Checks whether a file exists and is executable.
Function ResetTempfileModule Resets the random name generator of the tempfile module.
Function RetryOnSignal Calls a function again if it failed due to EINTR.
Function SetCloseOnExecFlag Sets or unsets the close-on-exec flag on a file descriptor.
Function SetNonblockFlag Sets or unsets the O_NONBLOCK flag on on a file descriptor.
Function TestDelay Sleep for a fixed amount of time.
def CloseFdNoError(fd, retries=5):

Close a file descriptor ignoring errors.

Parameters
fd:intthe file descriptor
retries:inthow many retries to make, in case we get any other error than EBADF
def GetClosedTempfile(*args, **kwargs):

Creates a temporary file and returns its path.

def IgnoreProcessNotFound(fn, *args, **kwargs):

Ignores ESRCH when calling a process-related function.

ESRCH is raised when a process is not found.

Returns
boolWhether process was found
def IgnoreSignals(fn, *args, **kwargs):

Tries to call a function ignoring failures due to EINTR.

def IsExecutable(filename):

Checks whether a file exists and is executable.

Parameters
filename:stringFilename
Returns
boolUndocumented
def ResetTempfileModule(_time=time.time):

Resets the random name generator of the tempfile module.

This function should be called after os.fork in the child process to ensure it creates a newly seeded random generator. Otherwise it would generate the same random parts as the parent process. If several processes race for the creation of a temporary file, this could lead to one not getting a temporary name.

def RetryOnSignal(fn, *args, **kwargs):

Calls a function again if it failed due to EINTR.

def SetCloseOnExecFlag(fd, enable):

Sets or unsets the close-on-exec flag on a file descriptor.

Parameters
fd:intFile descriptor
enable:boolWhether to set or unset it.
def SetNonblockFlag(fd, enable):

Sets or unsets the O_NONBLOCK flag on on a file descriptor.

Parameters
fd:intFile descriptor
enable:boolWhether to set or unset it
def TestDelay(duration):

Sleep for a fixed amount of time.

Parameters
duration:floatthe sleep duration, in seconds
Returns
(boolean, str)False for negative value, and an accompanying error message; True otherwise (and msg is None)