third_party: Update waf to verison 2.0.23
[Samba.git] / third_party / waf / waflib / extras / classic_runner.py
blobb08c794e880863ed0dda83d77a73684cb5f2ccc8
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # Thomas Nagy, 2021 (ita)
5 from waflib import Utils, Runner
7 """
8 Re-enable the classic threading system from waf 1.x
10 def configure(conf):
11 conf.load('classic_runner')
12 """
14 class TaskConsumer(Utils.threading.Thread):
15 """
16 Task consumers belong to a pool of workers
18 They wait for tasks in the queue and then use ``task.process(...)``
19 """
20 def __init__(self, spawner):
21 Utils.threading.Thread.__init__(self)
22 """
23 Obtain :py:class:`waflib.Task.TaskBase` instances from this queue.
24 """
25 self.spawner = spawner
26 self.daemon = True
27 self.start()
29 def run(self):
30 """
31 Loop over the tasks to execute
32 """
33 try:
34 self.loop()
35 except Exception:
36 pass
38 def loop(self):
39 """
40 Obtain tasks from :py:attr:`waflib.Runner.TaskConsumer.ready` and call
41 :py:meth:`waflib.Task.TaskBase.process`. If the object is a function, execute it.
42 """
43 master = self.spawner.master
44 while 1:
45 if not master.stop:
46 try:
47 tsk = master.ready.get()
48 if tsk:
49 tsk.log_display(tsk.generator.bld)
50 master.process_task(tsk)
51 else:
52 break
53 finally:
54 master.out.put(tsk)
56 class Spawner(object):
57 """
58 Daemon thread that consumes tasks from :py:class:`waflib.Runner.Parallel` producer and
59 spawns a consuming thread :py:class:`waflib.Runner.Consumer` for each
60 :py:class:`waflib.Task.Task` instance.
61 """
62 def __init__(self, master):
63 self.master = master
64 """:py:class:`waflib.Runner.Parallel` producer instance"""
66 self.pool = [TaskConsumer(self) for i in range(master.numjobs)]
68 Runner.Spawner = Spawner