class Job(Thread):
Constructors: Job.getJob(task, finished, name), Job(*args, **kwargs)
Job class that extends the Thread class with pause, resume, stop functionalities, and lists of running and paused jobs for reuse.
Job objects are not deleted immediately after they finished but pooled for reuse. They are only destroyed when the pressure on the pool was low for a certain time.
| Class Method | get |
Get a Job object, and set a task and a finished Callable for it to execute. The Job object is either taken from the paused list (if available), or a new one is created. After calling this method the Job instance is neither in the paused nor the running list... |
| Class Method | set |
Set parameters to balance the number of paused Jobs. |
| Method | __init__ |
Initialize a Job object. |
| Method | pause |
Pause a thread job. The job is removed from the running list (if still present there) and moved to the paused list. |
| Method | resume |
Resume a thread job. The job is removed from the paused list (if still present there) and moved to the running list. |
| Method | run |
Internal runner function for a job. |
| Method | set |
Set a task to run for the Job. |
| Method | stop |
Stop a thread job |
| Class Variable | __slots__ |
Slots for the class. |
| Class Variable | job |
Lock for the job lists. |
| Class Variable | paused |
List of paused jobs. |
| Class Variable | running |
List of running jobs. |
| Instance Variable | active |
Indicates that a job is active. An active job might be paused. |
| Instance Variable | finished |
Optional callback that is called after the task finished. |
| Instance Variable | name |
Name of the job. |
| Instance Variable | pause |
The flag used to pause the thread |
| Instance Variable | task |
Callback for the job's task. |
| Class Method | _balance |
Internal function to balance the number of paused and running jobs. |
| Class Variable | _balance |
Counter for current runs. Compares against balance. |
| Class Variable | _balance |
Number of requests for getting a new Job before a balance check. |
| Class Variable | _balance |
Factor to reduce the paused jobs (number of paused / balanceReduceFactor). |
| Class Variable | _balance |
Target balance between paused and running jobs (n paused for 1 running). |
Callable, finished: Callable | None = None, name: str | None = None) -> Job:
¶
Get a Job object, and set a task and a finished Callable for it to execute.
The Job object is either taken from the paused list (if available), or
a new one is created.
After calling this method the Job instance is neither in the paused nor the
running list. It is moved into the running list, for example, with the resume()
method.
| Parameters | |
task:Callable | A Callable. This must include arguments, so a lambda can be used here. |
finished:Callable | None | A Callable that is called when the task finished. |
name:str | None | Optional name of the job. |
| Returns | |
Job | The Job object. |
float | None = 3.0, balanceLatency: int | None = 1000, balanceReduceFactor: float | None = 2.0):
¶
Set parameters to balance the number of paused Jobs.
| Parameters | |
balancefloat | None | Target balance between paused and running jobs (n paused for 1 running). |
balanceint | None | Number of requests for getting a new Job before a balance check. |
balancefloat | None | Factor to reduce the paused jobs (number of paused / balanceReduceFactor). |
Initialize a Job object.
| Parameters | |
*args:Any | Positional job arguments. |
**kwargs:Any | Keyword job arguments. |
Pause a thread job. The job is removed from the running list (if still present there) and moved to the paused list.
| Returns | |
Job | The Job object. |
Resume a thread job. The job is removed from the paused list (if still present there) and moved to the running list.
| Returns | |
Job | The Job object. |
Callable, finished: Callable | None = None, name: str | None = None) -> Job:
¶
Set a task to run for the Job.
| Parameters | |
task:Callable | A Callable. This must include arguments, so a lambda can be used here. |
finished:Callable | None | A Callable that is called when the task finished. |
name:str | None | Optional name of the job. |
| Returns | |
Job | The Job object. |