qtoolkit.io.shell module#

class qtoolkit.io.shell.ShellIO(blocking=False, stdout_path='stdout', stderr_path='stderr', ps_username_strict=False, username_maxchars=None)[source]#

Bases: BaseSchedulerIO

Construct the ShellIO object.

Notes

On Linux, the ‘ps’ command truncates usernames to 7-8 characters, appending a “+” if truncated. To use the full username, set this variable to the desired maximum length. The ‘user’ field in the ps output will then be displayed as “user:NN”, where NN is this value. Previously, the default for the max number of characters for the username was 32. On macOS, usernames are not truncated and there is no option to fix the field width, so the default is now None.

Parameters:
  • blocking (bool) – Whether the execution should be blocking.

  • stdout_path (str or Path) – Path to the standard output file.

  • stderr_path (str or Path) – Path to the standard error file.

  • ps_username_strict (bool) – If set to True, the parsing of the username will raise an error if the username is truncated.

  • username_maxchars (int or None) – Width of the username field for the ps command. Default is None (which is 7-8 characters on Linux). On MacOS, setting the field explicitly is not allowed but the username is never truncated.

CANCEL_CMD: str | None = 'kill -9'#
get_submit_cmd(script_file: str | Path | None = 'submit.script') str[source]#

Get the command used to submit a given script to the queue.

Parameters:

script_file (str or Path) – Path of the script file to use.

header_template: str = 'exec > $${qout_path}\nexec 2> $${qerr_path}\n\necho $${job_name}\n$${qverbatim}\n'#
header_template_file: str = 'shell'#
job_id_regex: str | None = '^[1-9]\\d*$'#
parse_cancel_output(exit_code: int, stdout: str | bytes, stderr: str | bytes) CancelResult[source]#

Parse the output of the kill command.

parse_job_output(exit_code: int, stdout: str | bytes, stderr: str | bytes, job_id: str | None = None) QJob | None[source]#

Parse the output of the ps command and return the corresponding QJob object.

If the ps command returns multiple shell jobs, only the first corresponding QJob is returned. #TODO: should we check that there is only one job here ?

Parameters:
  • exit_code – Exit code of the ps command.

  • stdout – Standard output of the ps command.

  • stderr – Standard error of the ps command.

  • job_id – Job ID of the parsed job.

parse_jobs_list_output(exit_code: int, stdout: str | bytes, stderr: str | bytes, job_ids: list[str] | None = None) list[QJob][source]#

Parse the output of the ps command to list jobs.

Parameters:
  • exit_code – Exit code of the ps command.

  • stdout – Standard output of the ps command.

  • stderr – Standard error of the ps command.

  • job_ids – List of Job IDs of the jobs to return.

parse_submit_output(exit_code: int, stdout: str | bytes, stderr: str | bytes) SubmissionResult[source]#

Parse the output of the submission (background job).

property supported_qresources_keys: list#

List of attributes of QResources that are correctly handled by the _convert_qresources method. It is used to validate that the user does not pass an unsupported value, expecting to have an effect.

class qtoolkit.io.shell.ShellState(value)[source]#

Bases: QSubState

DEAD = 'X'#
DEFUNCT = 'Z'#
INTERRUPTIBLE_SLEEP = 'S'#
PAGING = 'W'#
RUNNING = 'R'#
STOPPED = 'T'#
STOPPED_DEBUGGER = 't'#
UNINTERRUPTIBLE_SLEEP = 'D'#
property qstate: QState#