toil.lib.misc

Attributes

logger

Exceptions

CalledProcessErrorStderr

Version of CalledProcessError that include stderr in the error message if it is set

Functions

get_public_ip()

Get the IP that this machine uses to contact the internet.

get_user_name()

Get the current user name, or a suitable substitute string if the user name

utc_now()

Return a datetime in the UTC timezone corresponding to right now.

unix_now_ms()

Return the current time in milliseconds since the Unix epoch.

slow_down(seconds)

Toil jobs that have completed are not allowed to have taken 0 seconds, but

printq(msg, quiet[, log])

This is for functions used simultaneously in Toil proper and in the admin scripts.

truncExpBackoff()

call_command(cmd, *args[, input, timeout, useCLocale, ...])

Simplified calling of external commands.

Module Contents

toil.lib.misc.logger
toil.lib.misc.get_public_ip()[source]

Get the IP that this machine uses to contact the internet.

If behind a NAT, this will still be this computer’s IP, and not the router’s.

Return type:

str

toil.lib.misc.get_user_name()[source]

Get the current user name, or a suitable substitute string if the user name is not available.

Return type:

str

toil.lib.misc.utc_now()[source]

Return a datetime in the UTC timezone corresponding to right now.

Return type:

datetime.datetime

toil.lib.misc.unix_now_ms()[source]

Return the current time in milliseconds since the Unix epoch.

Return type:

float

toil.lib.misc.slow_down(seconds)[source]

Toil jobs that have completed are not allowed to have taken 0 seconds, but Kubernetes timestamps round things to the nearest second. It is possible in some batch systems for a pod to have identical start and end timestamps.

This function takes a possibly 0 job length in seconds and enforces a minimum length to satisfy Toil.

Parameters:

seconds (float) – Timestamp difference

Returns:

seconds, or a small positive number if seconds is 0

Return type:

float

toil.lib.misc.printq(msg, quiet, log=False)[source]

This is for functions used simultaneously in Toil proper and in the admin scripts.

Our admin scripts “print” to stdout, while Toil proper uses logging. For a script that, for example, cleans up IAM, EC2, etc. cruft leftover after failed CI runs, we can call an AWS delete IAM role function, and this prints or logs progress (unless quiet is True), depending on whether the function is called in, say, the jobstore or a script.

Parameters:
  • msg (str) – The string to print or log to stdout.

  • quiet (bool) – Silent output to stdout.

  • log (bool) – Use logging (else “print” to the screen).

Return type:

None

toil.lib.misc.truncExpBackoff()[source]
Return type:

Iterator[float]

exception toil.lib.misc.CalledProcessErrorStderr(returncode, cmd, output=None, stderr=None)[source]

Bases: subprocess.CalledProcessError

Version of CalledProcessError that include stderr in the error message if it is set

__str__()[source]

Return str(self).

Return type:

str

toil.lib.misc.call_command(cmd, *args, input=None, timeout=None, useCLocale=True, env=None, quiet=False)[source]

Simplified calling of external commands.

If the process fails, CalledProcessErrorStderr is raised.

The captured stderr is always printed, regardless of if an exception occurs, so it can be logged.

Always logs the command at debug log level.

Parameters:
  • quiet (Optional[bool]) – If True, do not log the command output. If False (the default), do log the command output at debug log level.

  • useCLocale (bool) – If True, C locale is forced, to prevent failures that can occur in some batch systems when using UTF-8 locale.

  • cmd (List[str])

  • args (str)

  • input (Optional[str])

  • timeout (Optional[float])

  • env (Optional[Dict[str, str]])

Returns:

Command standard output, decoded as utf-8.

Return type:

str