summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/command.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-12-30 22:13:45 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-12-31 17:05:17 +0000
commit4c57c6eeecc43d0479380144f3073e61a8b43375 (patch)
tree75988728828f7c8528d89815ed1f48353f25d40a /bitbake/lib/bb/command.py
parent3cc9aed5a59d7b72b98ef40727102c98b031f911 (diff)
downloadpoky-4c57c6eeecc43d0479380144f3073e61a8b43375.tar.gz
bitbake: server/process: Run idle commands in a separate idle thread
When bitbake is off running heavier "idle" commands, it doesn't service it's command socket which means stopping/interrupting it is hard. It also means we can't "ping" from the UI to know if it is still alive. For those reasons, split idle command execution into it's own thread. The commands are generally already self containted so this is easier than expected. We do have to be careful to only handle inotify poll() from a single thread at a time. It also means we always have to use a thread lock when sending events since both the idle thread and the command thread may generate log messages (and hence events). The patch depends on previous fixes to the builtins locking in event.py and the heartbeat enable/disable changes as well as other locking additions. We use a condition to signal from the idle thread when other sections of code can continue, thanks to Joshua Watt for the review and tweaks squashed into this patch. We do have some sync points where we need to ensure any currently executing commands have finished before we can start a new async command for example. (Bitbake rev: 67dd9a5e84811df8869a82da6a37a41ee8fe94e2) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/command.py')
-rw-r--r--bitbake/lib/bb/command.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/bitbake/lib/bb/command.py b/bitbake/lib/bb/command.py
index 732327d84d..0706b89271 100644
--- a/bitbake/lib/bb/command.py
+++ b/bitbake/lib/bb/command.py
@@ -60,7 +60,7 @@ class Command:
60 # FIXME Add lock for this 60 # FIXME Add lock for this
61 self.currentAsyncCommand = None 61 self.currentAsyncCommand = None
62 62
63 def runCommand(self, commandline, ro_only = False): 63 def runCommand(self, commandline, process_server, ro_only=False):
64 command = commandline.pop(0) 64 command = commandline.pop(0)
65 65
66 # Ensure cooker is ready for commands 66 # Ensure cooker is ready for commands
@@ -84,7 +84,7 @@ class Command:
84 if not hasattr(command_method, 'readonly') or not getattr(command_method, 'readonly'): 84 if not hasattr(command_method, 'readonly') or not getattr(command_method, 'readonly'):
85 return None, "Not able to execute not readonly commands in readonly mode" 85 return None, "Not able to execute not readonly commands in readonly mode"
86 try: 86 try:
87 self.cooker.process_inotify_updates() 87 self.cooker.process_inotify_updates_apply()
88 if getattr(command_method, 'needconfig', True): 88 if getattr(command_method, 'needconfig', True):
89 self.cooker.updateCacheSync() 89 self.cooker.updateCacheSync()
90 result = command_method(self, commandline) 90 result = command_method(self, commandline)
@@ -100,7 +100,10 @@ class Command:
100 else: 100 else:
101 return result, None 101 return result, None
102 if self.currentAsyncCommand is not None: 102 if self.currentAsyncCommand is not None:
103 return None, "Busy (%s in progress)" % self.currentAsyncCommand[0] 103 # Wait for the idle loop to have cleared (30s max)
104 process_server.wait_for_idle(timeout=30)
105 if self.currentAsyncCommand is not None:
106 return None, "Busy (%s in progress)" % self.currentAsyncCommand[0]
104 if command not in CommandsAsync.__dict__: 107 if command not in CommandsAsync.__dict__:
105 return None, "No such command" 108 return None, "No such command"
106 self.currentAsyncCommand = (command, commandline) 109 self.currentAsyncCommand = (command, commandline)
@@ -109,7 +112,7 @@ class Command:
109 112
110 def runAsyncCommand(self): 113 def runAsyncCommand(self):
111 try: 114 try:
112 self.cooker.process_inotify_updates() 115 self.cooker.process_inotify_updates_apply()
113 if self.cooker.state in (bb.cooker.state.error, bb.cooker.state.shutdown, bb.cooker.state.forceshutdown): 116 if self.cooker.state in (bb.cooker.state.error, bb.cooker.state.shutdown, bb.cooker.state.forceshutdown):
114 # updateCache will trigger a shutdown of the parser 117 # updateCache will trigger a shutdown of the parser
115 # and then raise BBHandledException triggering an exit 118 # and then raise BBHandledException triggering an exit