asv_runner._aux
#
Module Contents#
Classes#
Module importer that only allows loading a given module from the given path. |
Functions#
Update sys.meta_path to include the SpecificImporter. |
|
Redirect stdout/stderr to a file, using posix |
|
Receive data of given size from a socket connection. |
|
Set CPU affinity based on the provided parameters. |
API#
- class asv_runner._aux.SpecificImporter(name, root)#
Module importer that only allows loading a given module from the given path.
Notes
Using this enables importing the asv benchmark suite without adding its parent directory to sys.path. The parent directory can in principle contain anything, including some version of the project module (common situation if asv.conf.json is on project repository top level).
Initialization
Initialize a new instance of
SpecificImporter
.Parameters
- name (
str
) The name of the module to load.
- root (
str
) The path to the directory containing the module.
- find_spec(fullname, path, target)#
Find the module specification for the given module.
Parameters
- fullname (
str
) The fully qualified name of the module.
- path (list or None)
The path for module search, or None if unavailable.
- target (object)
The target object to import.
Returns
- spec (
ModuleSpec
or None) The module specification if the module is found, or None otherwise.
Notes
This method is called by the import system to find the module specification for the requested module. If the requested module matches the name of the SpecificImporter instance, it returns the module specification using the
importlib.machinery.PathFinder
.- fullname (
- name (
- asv_runner._aux.update_sys_path(root)#
Update sys.meta_path to include the SpecificImporter.
Parameters
root
(str
): The path to the root directory.Notes
This function inserts the SpecificImporter into the
sys.meta_path
at the beginning, allowing the module to be imported using the SpecificImporter when it is encountered during the import process.
- asv_runner._aux.posix_redirect_output(filename=None, permanent=True)#
Redirect stdout/stderr to a file, using posix
dup2
.Parameters
- filename (
str
or None, optional) The name of the file to redirect the output to. If None, a temporary file will be created.
- permanent (
bool
, optional) Indicates whether the redirection is permanent or temporary. If False, the original stdout/stderr will be restored after the context is exited.
Yields
- filename (
str
) The name of the file where the output is redirected.
Notes
The function redirects the
stdout
andstderr
streams to a file using the posixdup2
function. It is typically used within awith
statement to encapsulate the code block where the redirection is desired.If
filename
is not provided, a temporary file will be created and used for redirection.If
permanent
isTrue
, the redirection will persist after the context is exited. IfFalse
, the originalstdout
/stderr
will be restored.- filename (
- asv_runner._aux.recvall(sock, size)#
Receive data of given size from a socket connection.
Parameters
- sock (socket object)
The socket connection to receive data from.
- size (
int
) The size of the data to receive, in bytes.
Returns
- data (
bytes
) The received data.
Raises
- RuntimeError
If the data received from the socket is less than the specified size.
Notes
The function receives data from a socket connection in multiple chunks until the specified size is reached. It ensures that all the required data is received before returning.
If the received data size is less than the specified size, a
RuntimeError
is raised indicating the failure to receive the complete data.
- asv_runner._aux.set_cpu_affinity_from_params(extra_params)#
Set CPU affinity based on the provided parameters.
Parameters
- extra_params (
dict
orNone
) Additional parameters containing CPU affinity information.
Notes
This function attempts to set the CPU affinity for the current process based on the provided parameters. It uses the
set_cpu_affinity
function internally to perform the actual affinity setting.If the
extra_params
dictionary contains a key “cpu_affinity” with a valid affinity list, the CPU affinity will be set accordingly.Raises
- BaseException
If setting the CPU affinity fails, an exception is raised and an error message is printed.
Example
extra_params = {"cpu_affinity": [0, 1]} set_cpu_affinity_from_params(extra_params)
- extra_params (