waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

classic_runner.py (1581B)


      1 #!/usr/bin/env python
      2 # encoding: utf-8
      3 # Thomas Nagy, 2021 (ita)
      4 
      5 from waflib import Utils, Runner
      6 
      7 """
      8 Re-enable the classic threading system from waf 1.x
      9 
     10 def configure(conf):
     11 	conf.load('classic_runner')
     12 """
     13 
     14 class TaskConsumer(Utils.threading.Thread):
     15 	"""
     16 	Task consumers belong to a pool of workers
     17 
     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()
     28 
     29 	def run(self):
     30 		"""
     31 		Loop over the tasks to execute
     32 		"""
     33 		try:
     34 			self.loop()
     35 		except Exception:
     36 			pass
     37 
     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)
     55 
     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"""
     65 
     66 		self.pool = [TaskConsumer(self) for i in range(master.numjobs)]
     67 
     68 Runner.Spawner = Spawner