duat.common
¶
Common tools.
-
class
duat.common.
Call
(fn, *args, **kwargs)[source]¶ Objectization of a call to be made. When an instance is called, such a call will be made.
-
class
duat.common.
MPCaller
(num_threads=2)[source]¶ MultiProcessing Caller. Makes calls using multiple subprocesses.
-
processes
¶ list of multiprocessing.Process – Processes managed by the instance.
-
abort
(interrupt=False)[source]¶ Remove all queued calls and ask processes to stop.
Parameters: interrupt – If True, terminate all processes.
-
add_call
(call)[source]¶ Add a call to the instance’s stack.
Parameters: call (Callable) – A function whose call method will be invoked by the processes. Consider using lambda functions or a Call
instance.
-
spawn_threads
(num_threads)[source]¶ Create the required number of processes and add them to the caller.
This does not remove previously created processes.
-
wait_calls
(blocking=True, respawn=False)[source]¶ Ask all processes to consume the queue and stop after that.
Parameters: - blocking (bool) – Whether to block the call, waiting for processes termination.
- respawn (bool) – If blocking is True, this indicates whether to respawn the threads after the calls finish. If blocking is not True this is ignored (no automatic respawn if non-blocking).
-
-
duat.common.
ensure_dir_exists
(path)[source]¶ Ensure a directory exists, creating it if needed.
Parameters: path (str) – The path to the directory. Raises: OSError
– An error occurred when creating the directory.
-
duat.common.
ensure_executable
(path, all_users=None)[source]¶ Ensure a file is executable.
Parameters: - path (str) – the path to the file.
- all_users (bool) – whether it should be make executable for the user or for all users.
-
duat.common.
head
(path, lines=10)[source]¶ Get the first lines of a file.
Parameters: - path (str) – Path to the file to read.
- lines (int) – Number of lines to read.
Returns: The lines found.
Return type: list
ofstr