summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2001-07-29 12:26:00 (GMT)
committerSteven Knight <knight@baldmt.com>2001-07-29 12:26:00 (GMT)
commit6a38dd15e4d36404cd3121e97e8308c2841987ef (patch)
treef565cca8eae2e0065260831b7473d35ab1c1c4e4 /src
parentd30b5d7c747a906752e5ab680743dade655e1537 (diff)
downloadSCons-6a38dd15e4d36404cd3121e97e8308c2841987ef.zip
SCons-6a38dd15e4d36404cd3121e97e8308c2841987ef.tar.gz
SCons-6a38dd15e4d36404cd3121e97e8308c2841987ef.tar.bz2
add the -j argument
Diffstat (limited to 'src')
-rw-r--r--src/scons/Job.py45
-rw-r--r--src/scons/JobTests.py18
2 files changed, 51 insertions, 12 deletions
diff --git a/src/scons/Job.py b/src/scons/Job.py
index 6da7e40..5e542d4 100644
--- a/src/scons/Job.py
+++ b/src/scons/Job.py
@@ -1,12 +1,55 @@
"""scons.Job
This module defines the Serial and Parallel classes that execute tasks to
-complete a build.
+complete a build. The Jobs class provides a higher level interface to start,
+stop, and wait on jobs.
"""
__revision__ = "Job.py __REVISION__ __DATE__ __DEVELOPER__"
+class Jobs:
+ """An instance of this class initializes N jobs, and provides
+ methods for starting, stopping, and waiting on all N jobs.
+ """
+
+ def __init__(self, num, taskmaster):
+ """
+ create 'num' jobs using the given taskmaster.
+
+ If 'num' is equal to 0, then a serial job will be used,
+ otherwise 'num' parallel jobs will be used.
+ """
+
+ if num > 1:
+ self.jobs = []
+ for i in range(num):
+ self.jobs.append(Parallel(taskmaster))
+ else:
+ self.jobs = [Serial(taskmaster)]
+
+ def start(self):
+ """start the jobs"""
+
+ for job in self.jobs:
+ job.start()
+
+ def wait(self):
+ """ wait for the jobs started with start() to finish"""
+
+ for job in self.jobs:
+ job.wait()
+
+ def stop(self):
+ """
+ stop the jobs started with start()
+
+ This function does not wait for the jobs to finish.
+ """
+
+ for job in self.jobs:
+ job.stop()
+
class Serial:
"""This class is used to execute tasks in series, and is more efficient
than Parallel, but is only appropriate for non-parallel builds. Only
diff --git a/src/scons/JobTests.py b/src/scons/JobTests.py
index 80ae6cd..4b8b558 100644
--- a/src/scons/JobTests.py
+++ b/src/scons/JobTests.py
@@ -121,15 +121,9 @@ class ParallelTestCase(unittest.TestCase):
raise NoThreadsException()
taskmaster = Taskmaster(num_tasks, self)
- jobs = []
- for i in range(num_jobs):
- jobs.append(scons.Job.Parallel(taskmaster))
-
- for job in jobs:
- job.start()
-
- for job in jobs:
- job.wait()
+ jobs = scons.Job.Jobs(num_jobs, taskmaster)
+ jobs.start()
+ jobs.wait()
self.failUnless(not taskmaster.tasks_were_serial(),
"the tasks were not executed in parallel")
@@ -143,8 +137,10 @@ class SerialTestCase(unittest.TestCase):
"test a serial job"
taskmaster = Taskmaster(num_tasks, self)
- job = scons.Job.Serial(taskmaster)
- job.start()
+ jobs = scons.Job.Jobs(1, taskmaster)
+ jobs.start()
+ jobs.wait()
+
self.failUnless(taskmaster.tasks_were_serial(),
"the tasks were not executed in series")
self.failUnless(taskmaster.all_tasks_are_executed(),