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

Class Jobs

source code

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 0x8926e9c>)
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: a) SIGINT: Keyboard interrupt b) SIGTERM: kill or system shutdown c) SIGHUP: Controlling shell exiting We handle all of these cases by stopping the taskmaster.
source code
 
_reset_sig_handler(self)
Restore the signal handlers to their previous state (before the call to _setup_sig_handler().
source code
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.

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

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:

  a) SIGINT: Keyboard interrupt
  b) SIGTERM: kill or system shutdown
  c) 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.