diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-05-12 08:30:35 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-05-16 23:32:40 +0100 |
commit | bc8971d122a02ed823acf0758da267dccc584f98 (patch) | |
tree | dd97329507feb611e64fad7f46d97d657f23eae4 /bitbake/bin/bitbake-worker | |
parent | e2f4d9f1ec694768b223decb59a9c768a2da962d (diff) | |
download | poky-bc8971d122a02ed823acf0758da267dccc584f98.tar.gz |
bitbake: bitbake: Convert to python 3 megacommit This needs breaking up into smaller changes.
(Bitbake rev: cf51f19aed208a75d38c14cd585d9b9f115e3ba3)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/bin/bitbake-worker')
-rwxr-xr-x | bitbake/bin/bitbake-worker | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/bitbake/bin/bitbake-worker b/bitbake/bin/bitbake-worker index 5fcffddd4d..dfce68d0c9 100755 --- a/bitbake/bin/bitbake-worker +++ b/bitbake/bin/bitbake-worker | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
2 | 2 | ||
3 | import os | 3 | import os |
4 | import sys | 4 | import sys |
@@ -10,8 +10,12 @@ import bb | |||
10 | import select | 10 | import select |
11 | import errno | 11 | import errno |
12 | import signal | 12 | import signal |
13 | import pickle | ||
13 | from multiprocessing import Lock | 14 | from multiprocessing import Lock |
14 | 15 | ||
16 | if sys.getfilesystemencoding() != "utf-8": | ||
17 | sys.exit("Please use a locale setting which supports utf-8.\nPython can't change the filesystem locale after loading so we need a utf-8 when python starts or things won't work.") | ||
18 | |||
15 | # Users shouldn't be running this code directly | 19 | # Users shouldn't be running this code directly |
16 | if len(sys.argv) != 2 or not sys.argv[1].startswith("decafbad"): | 20 | if len(sys.argv) != 2 or not sys.argv[1].startswith("decafbad"): |
17 | print("bitbake-worker is meant for internal execution by bitbake itself, please don't use it standalone.") | 21 | print("bitbake-worker is meant for internal execution by bitbake itself, please don't use it standalone.") |
@@ -30,19 +34,16 @@ if sys.argv[1].startswith("decafbadbad"): | |||
30 | # updates to log files for use with tail | 34 | # updates to log files for use with tail |
31 | try: | 35 | try: |
32 | if sys.stdout.name == '<stdout>': | 36 | if sys.stdout.name == '<stdout>': |
33 | sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) | 37 | import fcntl |
38 | fl = fcntl.fcntl(sys.stdout.fileno(), fcntl.F_GETFL) | ||
39 | fl |= os.O_SYNC | ||
40 | fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL, fl) | ||
41 | #sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) | ||
34 | except: | 42 | except: |
35 | pass | 43 | pass |
36 | 44 | ||
37 | logger = logging.getLogger("BitBake") | 45 | logger = logging.getLogger("BitBake") |
38 | 46 | ||
39 | try: | ||
40 | import cPickle as pickle | ||
41 | except ImportError: | ||
42 | import pickle | ||
43 | bb.msg.note(1, bb.msg.domain.Cache, "Importing cPickle failed. Falling back to a very slow implementation.") | ||
44 | |||
45 | |||
46 | worker_pipe = sys.stdout.fileno() | 47 | worker_pipe = sys.stdout.fileno() |
47 | bb.utils.nonblockingfd(worker_pipe) | 48 | bb.utils.nonblockingfd(worker_pipe) |
48 | # Need to guard against multiprocessing being used in child processes | 49 | # Need to guard against multiprocessing being used in child processes |
@@ -62,10 +63,10 @@ if 0: | |||
62 | consolelog.setFormatter(conlogformat) | 63 | consolelog.setFormatter(conlogformat) |
63 | logger.addHandler(consolelog) | 64 | logger.addHandler(consolelog) |
64 | 65 | ||
65 | worker_queue = "" | 66 | worker_queue = b"" |
66 | 67 | ||
67 | def worker_fire(event, d): | 68 | def worker_fire(event, d): |
68 | data = "<event>" + pickle.dumps(event) + "</event>" | 69 | data = b"<event>" + pickle.dumps(event) + b"</event>" |
69 | worker_fire_prepickled(data) | 70 | worker_fire_prepickled(data) |
70 | 71 | ||
71 | def worker_fire_prepickled(event): | 72 | def worker_fire_prepickled(event): |
@@ -91,7 +92,7 @@ def worker_child_fire(event, d): | |||
91 | global worker_pipe | 92 | global worker_pipe |
92 | global worker_pipe_lock | 93 | global worker_pipe_lock |
93 | 94 | ||
94 | data = "<event>" + pickle.dumps(event) + "</event>" | 95 | data = b"<event>" + pickle.dumps(event) + b"</event>" |
95 | try: | 96 | try: |
96 | worker_pipe_lock.acquire() | 97 | worker_pipe_lock.acquire() |
97 | worker_pipe.write(data) | 98 | worker_pipe.write(data) |
@@ -241,7 +242,7 @@ def fork_off_task(cfg, data, workerdata, fn, task, taskname, appends, taskdepdat | |||
241 | bb.utils.process_profilelog(profname) | 242 | bb.utils.process_profilelog(profname) |
242 | os._exit(ret) | 243 | os._exit(ret) |
243 | else: | 244 | else: |
244 | for key, value in envbackup.iteritems(): | 245 | for key, value in iter(envbackup.items()): |
245 | if value is None: | 246 | if value is None: |
246 | del os.environ[key] | 247 | del os.environ[key] |
247 | else: | 248 | else: |
@@ -258,22 +259,22 @@ class runQueueWorkerPipe(): | |||
258 | if pipeout: | 259 | if pipeout: |
259 | pipeout.close() | 260 | pipeout.close() |
260 | bb.utils.nonblockingfd(self.input) | 261 | bb.utils.nonblockingfd(self.input) |
261 | self.queue = "" | 262 | self.queue = b"" |
262 | 263 | ||
263 | def read(self): | 264 | def read(self): |
264 | start = len(self.queue) | 265 | start = len(self.queue) |
265 | try: | 266 | try: |
266 | self.queue = self.queue + self.input.read(102400) | 267 | self.queue = self.queue + (self.input.read(102400) or b"") |
267 | except (OSError, IOError) as e: | 268 | except (OSError, IOError) as e: |
268 | if e.errno != errno.EAGAIN: | 269 | if e.errno != errno.EAGAIN: |
269 | raise | 270 | raise |
270 | 271 | ||
271 | end = len(self.queue) | 272 | end = len(self.queue) |
272 | index = self.queue.find("</event>") | 273 | index = self.queue.find(b"</event>") |
273 | while index != -1: | 274 | while index != -1: |
274 | worker_fire_prepickled(self.queue[:index+8]) | 275 | worker_fire_prepickled(self.queue[:index+8]) |
275 | self.queue = self.queue[index+8:] | 276 | self.queue = self.queue[index+8:] |
276 | index = self.queue.find("</event>") | 277 | index = self.queue.find(b"</event>") |
277 | return (end > start) | 278 | return (end > start) |
278 | 279 | ||
279 | def close(self): | 280 | def close(self): |
@@ -289,7 +290,7 @@ class BitbakeWorker(object): | |||
289 | def __init__(self, din): | 290 | def __init__(self, din): |
290 | self.input = din | 291 | self.input = din |
291 | bb.utils.nonblockingfd(self.input) | 292 | bb.utils.nonblockingfd(self.input) |
292 | self.queue = "" | 293 | self.queue = b"" |
293 | self.cookercfg = None | 294 | self.cookercfg = None |
294 | self.databuilder = None | 295 | self.databuilder = None |
295 | self.data = None | 296 | self.data = None |
@@ -326,12 +327,12 @@ class BitbakeWorker(object): | |||
326 | except (OSError, IOError): | 327 | except (OSError, IOError): |
327 | pass | 328 | pass |
328 | if len(self.queue): | 329 | if len(self.queue): |
329 | self.handle_item("cookerconfig", self.handle_cookercfg) | 330 | self.handle_item(b"cookerconfig", self.handle_cookercfg) |
330 | self.handle_item("workerdata", self.handle_workerdata) | 331 | self.handle_item(b"workerdata", self.handle_workerdata) |
331 | self.handle_item("runtask", self.handle_runtask) | 332 | self.handle_item(b"runtask", self.handle_runtask) |
332 | self.handle_item("finishnow", self.handle_finishnow) | 333 | self.handle_item(b"finishnow", self.handle_finishnow) |
333 | self.handle_item("ping", self.handle_ping) | 334 | self.handle_item(b"ping", self.handle_ping) |
334 | self.handle_item("quit", self.handle_quit) | 335 | self.handle_item(b"quit", self.handle_quit) |
335 | 336 | ||
336 | for pipe in self.build_pipes: | 337 | for pipe in self.build_pipes: |
337 | self.build_pipes[pipe].read() | 338 | self.build_pipes[pipe].read() |
@@ -341,12 +342,12 @@ class BitbakeWorker(object): | |||
341 | 342 | ||
342 | 343 | ||
343 | def handle_item(self, item, func): | 344 | def handle_item(self, item, func): |
344 | if self.queue.startswith("<" + item + ">"): | 345 | if self.queue.startswith(b"<" + item + b">"): |
345 | index = self.queue.find("</" + item + ">") | 346 | index = self.queue.find(b"</" + item + b">") |
346 | while index != -1: | 347 | while index != -1: |
347 | func(self.queue[(len(item) + 2):index]) | 348 | func(self.queue[(len(item) + 2):index]) |
348 | self.queue = self.queue[(index + len(item) + 3):] | 349 | self.queue = self.queue[(index + len(item) + 3):] |
349 | index = self.queue.find("</" + item + ">") | 350 | index = self.queue.find(b"</" + item + b">") |
350 | 351 | ||
351 | def handle_cookercfg(self, data): | 352 | def handle_cookercfg(self, data): |
352 | self.cookercfg = pickle.loads(data) | 353 | self.cookercfg = pickle.loads(data) |
@@ -410,12 +411,12 @@ class BitbakeWorker(object): | |||
410 | self.build_pipes[pid].close() | 411 | self.build_pipes[pid].close() |
411 | del self.build_pipes[pid] | 412 | del self.build_pipes[pid] |
412 | 413 | ||
413 | worker_fire_prepickled("<exitcode>" + pickle.dumps((task, status)) + "</exitcode>") | 414 | worker_fire_prepickled(b"<exitcode>" + pickle.dumps((task, status)) + b"</exitcode>") |
414 | 415 | ||
415 | def handle_finishnow(self, _): | 416 | def handle_finishnow(self, _): |
416 | if self.build_pids: | 417 | if self.build_pids: |
417 | logger.info("Sending SIGTERM to remaining %s tasks", len(self.build_pids)) | 418 | logger.info("Sending SIGTERM to remaining %s tasks", len(self.build_pids)) |
418 | for k, v in self.build_pids.iteritems(): | 419 | for k, v in iter(self.build_pids.items()): |
419 | try: | 420 | try: |
420 | os.kill(-k, signal.SIGTERM) | 421 | os.kill(-k, signal.SIGTERM) |
421 | os.waitpid(-1, 0) | 422 | os.waitpid(-1, 0) |
@@ -425,6 +426,7 @@ class BitbakeWorker(object): | |||
425 | self.build_pipes[pipe].read() | 426 | self.build_pipes[pipe].read() |
426 | 427 | ||
427 | try: | 428 | try: |
429 | sys.stdin = sys.stdin.detach() | ||
428 | worker = BitbakeWorker(sys.stdin) | 430 | worker = BitbakeWorker(sys.stdin) |
429 | if not profiling: | 431 | if not profiling: |
430 | worker.serve() | 432 | worker.serve() |