jort API reference

jort.tracker module

class jort.tracker.Tracker(session_name=None, log_name='tracker.log', verbose=0, to_db=False)

Bases: object

A class to time sections of Python scripts by creating and closing timing blocks.

Parameters

session_namestr, optional

Name of job session, if saving jobs to database

log_namestr

Filename for timing logs

verboseint, optional

Options for verbosity. 0 for none, 1 for INFO, and 2 for DEBUG.

to_dbbool, optional

Save all block runtime details to database

ivar date_created:

time of initialization

ivar machine:

name of local machine

ivar blocks:

dict of Blocks

ivar open_block_payloads:

dict of job status payloads for open Blocks

ivar log_name:

log filename

iver to_db:

option to save all blocks to database

iver session_name:

name of job session

checkpoint(name=None, callbacks=[], to_db=False)

A checkpoint opens a timing block that closes at the next checkpoint. Note that the last checkpoint needs to be closed with stop().

start(name=None, date_created=None, is_checkpoint=False)

Open block and start timer. Creates initial job status payload for use with notifications.

Parameters

namestr

Block name

date_createdstr, optional

For an existing process, instead set this input as the creation date

is_checkpointbool, optional

Whether block start is a checkpoint (stops at next checkpoint)

stop(name=None, callbacks=[], to_db=False)

Close block and stop timer. Store start, stop, and elapsed times. Process job status payload and execute notification callbacks.

If block name isn’t supplied, get the most recent block (last in, first out; LIFO).

Parameters

namestr, optional

Block name

callbackslist, optional

List of optional notification callbacks

to_dbbool, optional

Save block runtime details to database

remove(name=None)

Option to remove block start instead of completing a profiling set, such as on catching an error.

Parameters

namestr, optional

Block name

clear_open()

Clear all open blocks / open job status payloads.

raise_error()

Update information payload with error details for the outermost block, to only be used within the except block during exception handling.

track(f=None, callbacks=[], to_db=False, report=False)

Function wrapper for tracker, to be used as a decorator. Creates a block with the input function’s name.

Without parameters / evaluation, the decorator simply creates the block and times the input function. With parameters, this method can execute callbacks and print a report.

Parameters

ffunc, optional

Function to decorate

callbackslist, optional

List of optional notification callbacks

to_dbbool, optional

Save block runtime details to database

reportbool, optional

Option to print tracker report at function completion

report(dec=1)

Print formatted runtime statistics for all blocks.

Parameters

decint

Decimal precision

exec(code_string)

Code string can be a series of statements, separated by newlines.

auto_line_monitor()
jort.tracker.track(f=None, callbacks=[], to_db=False, report=True)

Independent function wrapper, to be used as a decorator, that creates a one-off tracker.

Without parameters / evaluation, the decorator simply times the input function and prints a report by default. With parameters, this method can execute notification callbacks and control whether or not to print a report.

Parameters

ffunc, optional

Function to decorate

callbackslist, optional

List of optional notification callbacks

to_dbbool, optional

Save block runtime details to database

reportbool, optional

Option to print tracker report at function completion

jort.checkpoint module

jort.track_cli module

jort.track_cli.track_new(command, use_shell=False, store_stdout=False, save_filename=None, to_db=False, session_name=None, unique=False, send_text=False, send_email=False, verbose=False, update_period=-1)

Track execution time and details of new command line process.

Parameters

commandstr

Command to execute, which is spawned as a subprocess

use_shellbool, optional

Option to use shell execution for subprocess

store_stdoutbool, optional

Option to write command output to file

save_filenamestr, optional

Filename to which to save command output

to_dbbool, optional

Save all blocks to database

session_namestr, optional

Name of job session, if saving jobs to database

uniquebool, optional

Whether to skip job, if already successfully run and stored in database

send_textbool, optional

Option to send SMS notification on completion

send_emailbool, optional

Option to send e-mail notification on completion

verbosebool, optional

Option to control how much information is printed in stdout

update_periodint, optional

Number of seconds between each payload update and stdout write. If update_period=-1, as default, the only update occurs on completion.

jort.track_cli.track_existing(pid, to_db=False, session_name=None, send_text=False, send_email=False, verbose=False, update_period=-1)

Track execution time and details of existing command line process.

Parameters

pidint

Process ID of existing process

to_dbbool, optional

Save all blocks to database

session_namestr, optional

Name of job session, if saving jobs to database

send_textbool, optional

Option to send SMS notification on completion

send_emailbool, optional

Option to send e-mail notification on completion

verbosebool, optional

Option to control how much information is printed in stdout

update_periodint, optional

Number of seconds between each payload update. If update_period=-1, as default, the only update occurs on completion.

jort.reporting_callbacks module

class jort.reporting_callbacks.Callback

Bases: ABC

Abstract base class for notification callbacks.

abstract format_message(payload)

Format notification message as a string.

abstract execute(payload)

Send notification given job status payload.

class jort.reporting_callbacks.PrintReport

Bases: Callback

Print job runtime on completion.

format_message(payload)

Format notification message as a string.

execute(payload)

Send notification given job status payload.

class jort.reporting_callbacks.EmailNotification(email=None)

Bases: Callback

Send email notifications to and from your email account. Requires login credentials, which can be entered at the command line via jort config.

format_message(payload)

Format notification message as a string.

execute(payload)

Send notification given job status payload.

class jort.reporting_callbacks.TextNotification(receive_number=None)

Bases: Callback

Send SMS notifications to and from numbers managed by your Twilio account. Requires Twilio credentials, which can be entered at the command line via jort config.

format_message(payload)

Format notification message as a string.

execute(payload)

Send notification given job status payload.

jort.exceptions module

exception jort.exceptions.JortException

Bases: Exception

exception jort.exceptions.JortCredentialException

Bases: JortException

Exception for missing credentials.