job

Submodules

Attributes

NotifyEndType

logger

Classes

JobTimingInfo

Job

Handle a single Job.

EmptyJob

A job which does nothing.

ProcessJob

Specialized version of Job that spawn processes.

Package Contents

job.NotifyEndType
job.logger
class job.JobTimingInfo

Bases: tuple

start_time
stop_time
duration
class job.Job(uid: str, data: Any, notify_end: NotifyEndType)

Handle a single Job.

Variables:
  • slot (int) – number associated with the job during its execution. At a given time only one job have a given slot number.

  • start_time (datetime.datetime) – time at which job execution started or None if never started

  • stop_time (datetime.datetime) – time at which job execution ended or None if either the job was never run or if the job is still running

  • should_skip – indicator for the scheduler that the job should not be executed

  • interrupted – if True it means that job has been interrupted. Can be consequence of timeout or Ctrl-C pressed

  • queue_name – name of the queue in which the job has been placed

  • tokens – number of tokens (i.e: resources) consumed during the job execution

  • index – global index indicating the order in which jobs have been created. The index is used to implement the default ordering function needed to sort Jobs. In the context of e3.job.scheduler.Scheduler this means that by default jobs that are created first will have a higher priority.

Vartype:

bool

Vartype:

bool

Vartype:

str

Vartype:

int

Vartype:

int

lock
index_counter = 0
uid
data
notify_end
slot = 1
handle: threading.Thread | None = None
thread = None
__start_time: datetime.datetime | None = None
__stop_time: datetime.datetime | None = None
should_skip = False
interrupted = False
queue_name = 'default'
tokens = 1
property priority: int

Return job priority.

This is used in e3.job.scheduler.Scheduler.

record_start_time() None

Log the starting time of a job.

record_stop_time() None

Log the stopping time of a job.

property timing_info: JobTimingInfo

Retrieve some job’s timing information.

Returns:

a JobTimingInfo object

start(slot: int) None

Launch the job.

Parameters:

slot – slot number

abstractmethod run() None

Job activity.

property status: e3.anod.status.ReturnValue

Return he job’s status.

This is made a property because users of this class should not be allowed to set or change it value. The job’s status is … a property of the job!

interrupt() bool

Interrupt current job.

Returns:

True if interrupted, False if already interrupted

on_start(scheduler: e3.job.scheduler.Scheduler) None

Call whenever a job is started.

This allow the user to do some logging on job startup

on_finish(scheduler: e3.job.scheduler.Scheduler) None

Call whenever a job is finished.

This allow the user to do some logging on job termination

class job.EmptyJob(uid: str, data: Any, notify_end: collections.abc.Callable[[str], None], status: e3.anod.status.ReturnValue)

Bases: Job

A job which does nothing.

should_skip = True
__status
run() None

Job activity.

property status: e3.anod.status.ReturnValue

See Job.status’ description.

class job.ProcessJob(uid: str, data: Any, notify_end: collections.abc.Callable[[str], None])

Bases: Job

Specialized version of Job that spawn processes.

Variables:

proc_handle (e3.os.process.Run | None) – None when an object of this class is initialized. An e3.os.process.Run object after the “run” method is called.

proc_handle: e3.os.process.Run | None = None
__spawn_error = False
run() None

Run the job.

property status: e3.anod.status.ReturnValue

See Job.status’ description.

abstractmethod cmdline() list[str]

Return the command line of the process to be spawned.

Returns:

the command line

property cmd_options: dict

Process options.

Important note: don’t use PIPE for output or error parameters this can cause locking error in case the process is interrupted. The default redirect output and error to the console.

The pipe behavior can easily be emulated by writing to a file and modifying the run method to read the file content when the process finish.

Returns:

options for e3.os.process.Run as a dict

interrupt() bool

Kill running process tree.