Package ganeti :: Package utils :: Module wrapper
[hide private]
[frames] | no frames]

Module wrapper

source code

Utility functions wrapping other functions.

Functions [hide private]
(boolean, str)
TestDelay(duration)
Sleep for a fixed amount of time.
source code
 
CloseFdNoError(fd, retries=5)
Close a file descriptor ignoring errors.
source code
 
SetCloseOnExecFlag(fd, enable)
Sets or unsets the close-on-exec flag on a file descriptor.
source code
 
SetNonblockFlag(fd, enable)
Sets or unsets the O_NONBLOCK flag on on a file descriptor.
source code
 
RetryOnSignal(fn, *args, **kwargs)
Calls a function again if it failed due to EINTR.
source code
bool
IgnoreProcessNotFound(fn, *args, **kwargs)
Ignores ESRCH when calling a process-related function.
source code
 
IgnoreSignals(fn, *args, **kwargs)
Tries to call a function ignoring failures due to EINTR.
source code
 
GetClosedTempfile(*args, **kwargs)
Creates a temporary file and returns its path.
source code
bool
IsExecutable(filename)
Checks whether a file exists and is executable.
source code
 
ResetTempfileModule(_time=time.time)
Resets the random name generator of the tempfile module.
source code

Imports: sys, time, socket, errno, tempfile, fcntl, os, select, logging


Function Details [hide private]

TestDelay(duration)

source code 

Sleep for a fixed amount of time.

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

CloseFdNoError(fd, retries=5)

source code 

Close a file descriptor ignoring errors.

Parameters:
  • fd (int) - the file descriptor
  • retries (int) - how many retries to make, in case we get any other error than EBADF

SetCloseOnExecFlag(fd, enable)

source code 

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

Parameters:
  • fd (int) - File descriptor
  • enable (bool) - Whether to set or unset it.

SetNonblockFlag(fd, enable)

source code 

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

Parameters:
  • fd (int) - File descriptor
  • enable (bool) - Whether to set or unset it

IgnoreProcessNotFound(fn, *args, **kwargs)

source code 

Ignores ESRCH when calling a process-related function.

ESRCH is raised when a process is not found.

Returns: bool
Whether process was found

IsExecutable(filename)

source code 

Checks whether a file exists and is executable.

Parameters:
  • filename (string) - Filename
Returns: bool

ResetTempfileModule(_time=time.time)

source code 

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.