Package SCons :: Module Job :: Class Jobs
[hide private]
[frames] | no frames]

Class Jobs

source code

object --+
         |
        Jobs

An instance of this class initializes N jobs, and provides methods for starting, stopping, and waiting on all N jobs.
Instance Methods [hide private]
 
__init__(self, num, taskmaster)
create 'num' jobs using the given taskmaster.
source code
 
run(self, postfunc=<function <lambda> at 0x9c30ca4>)
Run the jobs.
source code
 
were_interrupted(self)
Returns whether the jobs were interrupted by a signal.
source code
 
_setup_sig_handler(self)
Setup an interrupt handler so that SCons can shutdown cleanly in various conditions:
source code
 
_reset_sig_handler(self)
Restore the signal handlers to their previous state (before the call to _setup_sig_handler().
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, num, taskmaster)
(Constructor)

source code 

create 'num' jobs using the given taskmaster.

If 'num' is 1 or less, then a serial job will be used, otherwise a parallel job with 'num' worker threads will be used.

The 'num_jobs' attribute will be set to the actual number of jobs allocated. If more than one job is requested but the Parallel class can't do it, it gets reset to 1. Wrapping interfaces that care should check the value of 'num_jobs' after initialization.

Overrides: object.__init__

run(self, postfunc=<function <lambda> at 0x9c30ca4>)

source code 

Run the jobs.

postfunc() will be invoked after the jobs has run. It will be invoked even if the jobs are interrupted by a keyboard interrupt (well, in fact by a signal such as either SIGINT, SIGTERM or SIGHUP). The execution of postfunc() is protected against keyboard interrupts and is guaranteed to run to completion.

_setup_sig_handler(self)

source code 

Setup an interrupt handler so that SCons can shutdown cleanly in various conditions:

  1. SIGINT: Keyboard interrupt
  2. SIGTERM: kill or system shutdown
  3. SIGHUP: Controlling shell exiting

We handle all of these cases by stopping the taskmaster. It turns out that it very difficult to stop the build process by throwing asynchronously an exception such as KeyboardInterrupt. For example, the python Condition variables (threading.Condition) and queue's do not seem to asynchronous-exception-safe. It would require adding a whole bunch of try/finally block and except KeyboardInterrupt all over the place.

Note also that we have to be careful to handle the case when SCons forks before executing another process. In that case, we want the child to exit immediately.