diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-12-20 14:17:49 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-12-31 17:05:17 +0000 |
commit | cb8efd4d20d7643632b04ce8350c1b58aed49122 (patch) | |
tree | 6b8bbc5edf3e53fcb148b12a60861d7237356d9d | |
parent | 2c5bc0379675c11a84056b2ac5ccaad766c3e766 (diff) | |
download | poky-cb8efd4d20d7643632b04ce8350c1b58aed49122.tar.gz |
bitbake: event: Add enable/disable heartbeat code
Currently heartbeat events are always generated by the server whilst it is
active. Change this so they only appear when builds are running, which is
when most code would expect to be executed. This removes a number of races
around changes in the datastore which can happen outside of builds.
(Bitbake rev: 8c36c90afc392980d999a981a924dc7d22e2766e)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/cooker.py | 4 | ||||
-rw-r--r-- | bitbake/lib/bb/event.py | 9 | ||||
-rw-r--r-- | bitbake/lib/bb/server/process.py | 4 |
3 files changed, 15 insertions, 2 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py index 4e49b0e90b..c712744382 100644 --- a/bitbake/lib/bb/cooker.py +++ b/bitbake/lib/bb/cooker.py | |||
@@ -1467,6 +1467,7 @@ class BBCooker: | |||
1467 | buildname = self.databuilder.mcdata[mc].getVar("BUILDNAME") | 1467 | buildname = self.databuilder.mcdata[mc].getVar("BUILDNAME") |
1468 | if fireevents: | 1468 | if fireevents: |
1469 | bb.event.fire(bb.event.BuildStarted(buildname, [item]), self.databuilder.mcdata[mc]) | 1469 | bb.event.fire(bb.event.BuildStarted(buildname, [item]), self.databuilder.mcdata[mc]) |
1470 | bb.event.enable_heartbeat() | ||
1470 | 1471 | ||
1471 | # Execute the runqueue | 1472 | # Execute the runqueue |
1472 | runlist = [[mc, item, task, fn]] | 1473 | runlist = [[mc, item, task, fn]] |
@@ -1500,6 +1501,7 @@ class BBCooker: | |||
1500 | if not retval: | 1501 | if not retval: |
1501 | if fireevents: | 1502 | if fireevents: |
1502 | bb.event.fire(bb.event.BuildCompleted(len(rq.rqdata.runtaskentries), buildname, item, failures, interrupted), self.databuilder.mcdata[mc]) | 1503 | bb.event.fire(bb.event.BuildCompleted(len(rq.rqdata.runtaskentries), buildname, item, failures, interrupted), self.databuilder.mcdata[mc]) |
1504 | bb.event.disable_heartbeat() | ||
1503 | self.command.finishAsyncCommand(msg) | 1505 | self.command.finishAsyncCommand(msg) |
1504 | # We trashed self.recipecaches above | 1506 | # We trashed self.recipecaches above |
1505 | self.parsecache_valid = False | 1507 | self.parsecache_valid = False |
@@ -1545,6 +1547,7 @@ class BBCooker: | |||
1545 | for mc in self.multiconfigs: | 1547 | for mc in self.multiconfigs: |
1546 | bb.event.fire(bb.event.BuildCompleted(len(rq.rqdata.runtaskentries), buildname, targets, failures, interrupted), self.databuilder.mcdata[mc]) | 1548 | bb.event.fire(bb.event.BuildCompleted(len(rq.rqdata.runtaskentries), buildname, targets, failures, interrupted), self.databuilder.mcdata[mc]) |
1547 | finally: | 1549 | finally: |
1550 | bb.event.disable_heartbeat() | ||
1548 | self.command.finishAsyncCommand(msg) | 1551 | self.command.finishAsyncCommand(msg) |
1549 | return False | 1552 | return False |
1550 | if retval is True: | 1553 | if retval is True: |
@@ -1578,6 +1581,7 @@ class BBCooker: | |||
1578 | 1581 | ||
1579 | for mc in self.multiconfigs: | 1582 | for mc in self.multiconfigs: |
1580 | bb.event.fire(bb.event.BuildStarted(buildname, ntargets), self.databuilder.mcdata[mc]) | 1583 | bb.event.fire(bb.event.BuildStarted(buildname, ntargets), self.databuilder.mcdata[mc]) |
1584 | bb.event.enable_heartbeat() | ||
1581 | 1585 | ||
1582 | rq = bb.runqueue.RunQueue(self, self.data, self.recipecaches, taskdata, runlist) | 1586 | rq = bb.runqueue.RunQueue(self, self.data, self.recipecaches, taskdata, runlist) |
1583 | if 'universe' in targets: | 1587 | if 'universe' in targets: |
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py index 303b7a943f..db90724444 100644 --- a/bitbake/lib/bb/event.py +++ b/bitbake/lib/bb/event.py | |||
@@ -69,6 +69,7 @@ _eventfilter = None | |||
69 | _uiready = False | 69 | _uiready = False |
70 | _thread_lock = threading.Lock() | 70 | _thread_lock = threading.Lock() |
71 | _thread_lock_enabled = False | 71 | _thread_lock_enabled = False |
72 | _heartbeat_enabled = False | ||
72 | 73 | ||
73 | def enable_threadlock(): | 74 | def enable_threadlock(): |
74 | global _thread_lock_enabled | 75 | global _thread_lock_enabled |
@@ -78,6 +79,14 @@ def disable_threadlock(): | |||
78 | global _thread_lock_enabled | 79 | global _thread_lock_enabled |
79 | _thread_lock_enabled = False | 80 | _thread_lock_enabled = False |
80 | 81 | ||
82 | def enable_heartbeat(): | ||
83 | global _heartbeat_enabled | ||
84 | _heartbeat_enabled = True | ||
85 | |||
86 | def disable_heartbeat(): | ||
87 | global _heartbeat_enabled | ||
88 | _heartbeat_enabled = False | ||
89 | |||
81 | def execute_handler(name, handler, event, d): | 90 | def execute_handler(name, handler, event, d): |
82 | event.data = d | 91 | event.data = d |
83 | try: | 92 | try: |
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py index 586d46af88..91eb6e0ad9 100644 --- a/bitbake/lib/bb/server/process.py +++ b/bitbake/lib/bb/server/process.py | |||
@@ -382,7 +382,7 @@ class ProcessServer(): | |||
382 | 382 | ||
383 | # Create new heartbeat event? | 383 | # Create new heartbeat event? |
384 | now = time.time() | 384 | now = time.time() |
385 | if now >= self.next_heartbeat: | 385 | if bb.event._heartbeat_enabled and now >= self.next_heartbeat: |
386 | # We might have missed heartbeats. Just trigger once in | 386 | # We might have missed heartbeats. Just trigger once in |
387 | # that case and continue after the usual delay. | 387 | # that case and continue after the usual delay. |
388 | self.next_heartbeat += self.heartbeat_seconds | 388 | self.next_heartbeat += self.heartbeat_seconds |
@@ -396,7 +396,7 @@ class ProcessServer(): | |||
396 | if not isinstance(exc, bb.BBHandledException): | 396 | if not isinstance(exc, bb.BBHandledException): |
397 | logger.exception('Running heartbeat function') | 397 | logger.exception('Running heartbeat function') |
398 | self.quit = True | 398 | self.quit = True |
399 | if nextsleep and now + nextsleep > self.next_heartbeat: | 399 | if nextsleep and bb.event._heartbeat_enabled and now + nextsleep > self.next_heartbeat: |
400 | # Shorten timeout so that we we wake up in time for | 400 | # Shorten timeout so that we we wake up in time for |
401 | # the heartbeat. | 401 | # the heartbeat. |
402 | nextsleep = self.next_heartbeat - now | 402 | nextsleep = self.next_heartbeat - now |