diff options
Diffstat (limited to 'bitbake')
| -rw-r--r-- | bitbake/lib/bb/server/process.py | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py index 5b4d92dc80..2be4588a4f 100644 --- a/bitbake/lib/bb/server/process.py +++ b/bitbake/lib/bb/server/process.py | |||
| @@ -35,6 +35,10 @@ logger = logging.getLogger('BitBake') | |||
| 35 | class ProcessTimeout(SystemExit): | 35 | class ProcessTimeout(SystemExit): |
| 36 | pass | 36 | pass |
| 37 | 37 | ||
| 38 | def serverlog(msg): | ||
| 39 | print(msg) | ||
| 40 | sys.stdout.flush() | ||
| 41 | |||
| 38 | class ProcessServer(): | 42 | class ProcessServer(): |
| 39 | profile_filename = "profile.log" | 43 | profile_filename = "profile.log" |
| 40 | profile_processed_filename = "profile.log.processed" | 44 | profile_processed_filename = "profile.log.processed" |
| @@ -73,7 +77,7 @@ class ProcessServer(): | |||
| 73 | if self.xmlrpcinterface[0]: | 77 | if self.xmlrpcinterface[0]: |
| 74 | self.xmlrpc = bb.server.xmlrpcserver.BitBakeXMLRPCServer(self.xmlrpcinterface, self.cooker, self) | 78 | self.xmlrpc = bb.server.xmlrpcserver.BitBakeXMLRPCServer(self.xmlrpcinterface, self.cooker, self) |
| 75 | 79 | ||
| 76 | print("Bitbake XMLRPC server address: %s, server port: %s" % (self.xmlrpc.host, self.xmlrpc.port)) | 80 | serverlog("Bitbake XMLRPC server address: %s, server port: %s" % (self.xmlrpc.host, self.xmlrpc.port)) |
| 77 | 81 | ||
| 78 | try: | 82 | try: |
| 79 | self.bitbake_lock.seek(0) | 83 | self.bitbake_lock.seek(0) |
| @@ -84,7 +88,7 @@ class ProcessServer(): | |||
| 84 | self.bitbake_lock.write("%s\n" % (os.getpid())) | 88 | self.bitbake_lock.write("%s\n" % (os.getpid())) |
| 85 | self.bitbake_lock.flush() | 89 | self.bitbake_lock.flush() |
| 86 | except Exception as e: | 90 | except Exception as e: |
| 87 | print("Error writing to lock file: %s" % str(e)) | 91 | serverlog("Error writing to lock file: %s" % str(e)) |
| 88 | pass | 92 | pass |
| 89 | 93 | ||
| 90 | if self.cooker.configuration.profile: | 94 | if self.cooker.configuration.profile: |
| @@ -98,7 +102,7 @@ class ProcessServer(): | |||
| 98 | 102 | ||
| 99 | prof.dump_stats("profile.log") | 103 | prof.dump_stats("profile.log") |
| 100 | bb.utils.process_profilelog("profile.log") | 104 | bb.utils.process_profilelog("profile.log") |
| 101 | print("Raw profiling information saved to profile.log and processed statistics to profile.log.processed") | 105 | serverlog("Raw profiling information saved to profile.log and processed statistics to profile.log.processed") |
| 102 | 106 | ||
| 103 | else: | 107 | else: |
| 104 | ret = self.main() | 108 | ret = self.main() |
| @@ -118,10 +122,10 @@ class ProcessServer(): | |||
| 118 | if self.xmlrpc: | 122 | if self.xmlrpc: |
| 119 | fds.append(self.xmlrpc) | 123 | fds.append(self.xmlrpc) |
| 120 | seendata = False | 124 | seendata = False |
| 121 | print("Entering server connection loop") | 125 | serverlog("Entering server connection loop") |
| 122 | 126 | ||
| 123 | def disconnect_client(self, fds): | 127 | def disconnect_client(self, fds): |
| 124 | print("Disconnecting Client") | 128 | serverlog("Disconnecting Client") |
| 125 | if self.controllersock: | 129 | if self.controllersock: |
| 126 | fds.remove(self.controllersock) | 130 | fds.remove(self.controllersock) |
| 127 | self.controllersock.close() | 131 | self.controllersock.close() |
| @@ -139,12 +143,12 @@ class ProcessServer(): | |||
| 139 | self.haveui = False | 143 | self.haveui = False |
| 140 | ready = select.select(fds,[],[],0)[0] | 144 | ready = select.select(fds,[],[],0)[0] |
| 141 | if newconnections: | 145 | if newconnections: |
| 142 | print("Starting new client") | 146 | serverlog("Starting new client") |
| 143 | conn = newconnections.pop(-1) | 147 | conn = newconnections.pop(-1) |
| 144 | fds.append(conn) | 148 | fds.append(conn) |
| 145 | self.controllersock = conn | 149 | self.controllersock = conn |
| 146 | elif self.timeout is None and not ready: | 150 | elif self.timeout is None and not ready: |
| 147 | print("No timeout, exiting.") | 151 | serverlog("No timeout, exiting.") |
| 148 | self.quit = True | 152 | self.quit = True |
| 149 | 153 | ||
| 150 | self.lastui = time.time() | 154 | self.lastui = time.time() |
| @@ -153,17 +157,17 @@ class ProcessServer(): | |||
| 153 | while select.select([self.sock],[],[],0)[0]: | 157 | while select.select([self.sock],[],[],0)[0]: |
| 154 | controllersock, address = self.sock.accept() | 158 | controllersock, address = self.sock.accept() |
| 155 | if self.controllersock: | 159 | if self.controllersock: |
| 156 | print("Queuing %s (%s)" % (str(ready), str(newconnections))) | 160 | serverlog("Queuing %s (%s)" % (str(ready), str(newconnections))) |
| 157 | newconnections.append(controllersock) | 161 | newconnections.append(controllersock) |
| 158 | else: | 162 | else: |
| 159 | print("Accepting %s (%s)" % (str(ready), str(newconnections))) | 163 | serverlog("Accepting %s (%s)" % (str(ready), str(newconnections))) |
| 160 | self.controllersock = controllersock | 164 | self.controllersock = controllersock |
| 161 | fds.append(controllersock) | 165 | fds.append(controllersock) |
| 162 | if self.controllersock in ready: | 166 | if self.controllersock in ready: |
| 163 | try: | 167 | try: |
| 164 | print("Processing Client") | 168 | serverlog("Processing Client") |
| 165 | ui_fds = recvfds(self.controllersock, 3) | 169 | ui_fds = recvfds(self.controllersock, 3) |
| 166 | print("Connecting Client") | 170 | serverlog("Connecting Client") |
| 167 | 171 | ||
| 168 | # Where to write events to | 172 | # Where to write events to |
| 169 | writer = ConnectionWriter(ui_fds[0]) | 173 | writer = ConnectionWriter(ui_fds[0]) |
| @@ -187,14 +191,14 @@ class ProcessServer(): | |||
| 187 | 191 | ||
| 188 | if not self.timeout == -1.0 and not self.haveui and self.timeout and \ | 192 | if not self.timeout == -1.0 and not self.haveui and self.timeout and \ |
| 189 | (self.lastui + self.timeout) < time.time(): | 193 | (self.lastui + self.timeout) < time.time(): |
| 190 | print("Server timeout, exiting.") | 194 | serverlog("Server timeout, exiting.") |
| 191 | self.quit = True | 195 | self.quit = True |
| 192 | 196 | ||
| 193 | # If we don't see a UI connection within maxuiwait, its unlikely we're going to see | 197 | # If we don't see a UI connection within maxuiwait, its unlikely we're going to see |
| 194 | # one. We have had issue with processes hanging indefinitely so timing out UI-less | 198 | # one. We have had issue with processes hanging indefinitely so timing out UI-less |
| 195 | # servers is useful. | 199 | # servers is useful. |
| 196 | if not self.hadanyui and not self.xmlrpc and not self.timeout and (self.lastui + self.maxuiwait) < time.time(): | 200 | if not self.hadanyui and not self.xmlrpc and not self.timeout and (self.lastui + self.maxuiwait) < time.time(): |
| 197 | print("No UI connection within max timeout, exiting to avoid infinite loop.") | 201 | serverlog("No UI connection within max timeout, exiting to avoid infinite loop.") |
| 198 | self.quit = True | 202 | self.quit = True |
| 199 | 203 | ||
| 200 | if self.command_channel in ready: | 204 | if self.command_channel in ready: |
| @@ -209,7 +213,7 @@ class ProcessServer(): | |||
| 209 | self.quit = True | 213 | self.quit = True |
| 210 | continue | 214 | continue |
| 211 | try: | 215 | try: |
| 212 | print("Running command %s" % command) | 216 | serverlog("Running command %s" % command) |
| 213 | self.command_channel_reply.send(self.cooker.command.runCommand(command)) | 217 | self.command_channel_reply.send(self.cooker.command.runCommand(command)) |
| 214 | except Exception as e: | 218 | except Exception as e: |
| 215 | logger.exception('Exception in server main event loop running command %s (%s)' % (command, str(e))) | 219 | logger.exception('Exception in server main event loop running command %s (%s)' % (command, str(e))) |
| @@ -236,9 +240,9 @@ class ProcessServer(): | |||
| 236 | ready = self.idle_commands(.1, fds) | 240 | ready = self.idle_commands(.1, fds) |
| 237 | 241 | ||
| 238 | if len(threading.enumerate()) != 1: | 242 | if len(threading.enumerate()) != 1: |
| 239 | print("More than one thread left?: " + str(threading.enumerate())) | 243 | serverlog("More than one thread left?: " + str(threading.enumerate())) |
| 240 | 244 | ||
| 241 | print("Exiting") | 245 | serverlog("Exiting") |
| 242 | # Remove the socket file so we don't get any more connections to avoid races | 246 | # Remove the socket file so we don't get any more connections to avoid races |
| 243 | try: | 247 | try: |
| 244 | os.unlink(self.sockname) | 248 | os.unlink(self.sockname) |
| @@ -296,7 +300,7 @@ class ProcessServer(): | |||
| 296 | msg = "Delaying shutdown due to active processes which appear to be holding bitbake.lock" | 300 | msg = "Delaying shutdown due to active processes which appear to be holding bitbake.lock" |
| 297 | if procs: | 301 | if procs: |
| 298 | msg += ":\n%s" % str(procs.decode("utf-8")) | 302 | msg += ":\n%s" % str(procs.decode("utf-8")) |
| 299 | print(msg) | 303 | serverlog(msg) |
| 300 | 304 | ||
| 301 | def idle_commands(self, delay, fds=None): | 305 | def idle_commands(self, delay, fds=None): |
| 302 | nextsleep = delay | 306 | nextsleep = delay |
| @@ -485,8 +489,7 @@ def execServer(lockfd, readypipeinfd, lockname, sockname, server_timeout, xmlrpc | |||
| 485 | import bb.cookerdata | 489 | import bb.cookerdata |
| 486 | import bb.cooker | 490 | import bb.cooker |
| 487 | 491 | ||
| 488 | print(start_log_format % (os.getpid(), datetime.datetime.now().strftime(start_log_datetime_format))) | 492 | serverlog(start_log_format % (os.getpid(), datetime.datetime.now().strftime(start_log_datetime_format))) |
| 489 | sys.stdout.flush() | ||
| 490 | 493 | ||
| 491 | try: | 494 | try: |
| 492 | bitbake_lock = os.fdopen(lockfd, "w") | 495 | bitbake_lock = os.fdopen(lockfd, "w") |
| @@ -515,8 +518,7 @@ def execServer(lockfd, readypipeinfd, lockname, sockname, server_timeout, xmlrpc | |||
| 515 | writer.send("r") | 518 | writer.send("r") |
| 516 | writer.close() | 519 | writer.close() |
| 517 | server.cooker = cooker | 520 | server.cooker = cooker |
| 518 | print("Started bitbake server pid %d" % os.getpid()) | 521 | serverlog("Started bitbake server pid %d" % os.getpid()) |
| 519 | sys.stdout.flush() | ||
| 520 | 522 | ||
| 521 | server.run() | 523 | server.run() |
| 522 | finally: | 524 | finally: |
