From c30630548b66e59e055e372bec4736d118bac131 Mon Sep 17 00:00:00 2001 From: Chris Larson Date: Mon, 20 Dec 2010 15:23:13 -0500 Subject: [PATCH] runqueue: resurrect use of file objects for pipein/pipeout Signed-off-by: Chris Larson --- lib/bb/event.py | 6 +----- lib/bb/runqueue.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/bb/event.py b/lib/bb/event.py index 647d02935a8..322ce990539 100644 --- a/lib/bb/event.py +++ b/lib/bb/event.py @@ -126,11 +126,7 @@ def fire(event, d): def worker_fire(event, d): data = "" + pickle.dumps(event) + "" - try: - if os.write(worker_pipe, data) != len (data): - print("Error sending event to server (short write)") - except OSError: - sys.exit(1) + worker_pipe.write(data) def fire_from_worker(event, d): if not event.startswith("") or not event.endswith(""): diff --git a/lib/bb/runqueue.py b/lib/bb/runqueue.py index 14d174d4a98..ba1d084732c 100644 --- a/lib/bb/runqueue.py +++ b/lib/bb/runqueue.py @@ -1056,11 +1056,13 @@ class RunQueueExecute: sys.stderr.flush() try: pipein, pipeout = os.pipe() + pipein = os.fdopen(pipein, 'rb', 4096) + pipeout = os.fdopen(pipeout, 'wb', 0) pid = os.fork() except OSError as e: bb.msg.fatal(bb.msg.domain.RunQueue, "fork failed: %d (%s)" % (e.errno, e.strerror)) if pid == 0: - os.close(pipein) + pipein.close() # Save out the PID so that the event can include it the # events bb.event.worker_pid = os.getpid() @@ -1576,17 +1578,17 @@ class runQueuePipe(): Abstraction for a pipe between a worker thread and the server """ def __init__(self, pipein, pipeout, d): - self.fd = pipein - os.close(pipeout) - fcntl.fcntl(self.fd, fcntl.F_SETFL, fcntl.fcntl(self.fd, fcntl.F_GETFL) | os.O_NONBLOCK) + self.input = pipein + pipeout.close() + fcntl.fcntl(self.input, fcntl.F_SETFL, fcntl.fcntl(self.input, fcntl.F_GETFL) | os.O_NONBLOCK) self.queue = "" self.d = d def read(self): start = len(self.queue) try: - self.queue = self.queue + os.read(self.fd, 1024) - except OSError: + self.queue = self.queue + self.input.read(1024) + except (OSError, IOError): pass end = len(self.queue) index = self.queue.find("") @@ -1601,4 +1603,4 @@ class runQueuePipe(): continue if len(self.queue) > 0: print("Warning, worker left partial message") - os.close(self.fd) + self.input.close() -- 2.47.3