jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.5KB

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