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

Module wrapper

source code

Utility functions wrapping other functions.

Functions [hide private]
boolean
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
 
ResetTempfileModule()
Resets the random name generator of the tempfile module.
source code

Imports: 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
Returns: boolean
False for negative value, True otherwise

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

ResetTempfileModule()

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.