diff options
author | Zac Medico <zmedico@gentoo.org> | 2010-09-02 00:05:06 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-09-02 00:05:06 -0700 |
commit | 252fa9a50c264e9827c42c631291749ad62d0f4d (patch) | |
tree | 65a79cae3f0b770f60b344fbc14d65e67c9c78d1 /bin | |
parent | 7dfbdb9025376df95af58f42e304f9ef627576e6 (diff) | |
download | portage-252fa9a50c264e9827c42c631291749ad62d0f4d.tar.gz portage-252fa9a50c264e9827c42c631291749ad62d0f4d.tar.bz2 portage-252fa9a50c264e9827c42c631291749ad62d0f4d.zip |
Adjust EbuildIpcDaemon pickle read and write code in order to ensure
atomc reading and writing of whole pickles. This should be the least
error-prone approach, given the non-blocking nature of the streams.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/ebuild-ipc.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/bin/ebuild-ipc.py b/bin/ebuild-ipc.py index cbb8c5570..52fb08226 100755 --- a/bin/ebuild-ipc.py +++ b/bin/ebuild-ipc.py @@ -48,13 +48,35 @@ class EbuildIpc(object): def _communicate(self, args): input_fd = os.open(self.ipc_out_fifo, os.O_RDONLY|os.O_NONBLOCK) - input_file = os.fdopen(input_fd, 'rb') - output_file = open(self.ipc_in_fifo, 'wb') - pickle.dump(args, output_file) + + # File streams are in unbuffered mode since we do atomic + # read and write of whole pickles. + input_file = os.fdopen(input_fd, 'rb', 0) + output_file = open(self.ipc_in_fifo, 'wb', 0) + + # Write the whole pickle in a single atomic write() call, + # since the reader is in non-blocking mode and we want + # it to get the whole pickle at once. + output_file.write(pickle.dumps(args)) output_file.flush() events = select.select([input_file], [], []) - reply = pickle.load(input_file) + + # Read the whole pickle in a single read() call since + # this stream is in non-blocking mode and pickle.load() + # has been known to raise the following exception when + # reading from a non-blocking stream: + # + # File "/usr/lib64/python2.6/pickle.py", line 1370, in load + # return Unpickler(file).load() + # File "/usr/lib64/python2.6/pickle.py", line 858, in load + # dispatch[key](self) + # File "/usr/lib64/python2.6/pickle.py", line 1195, in load_setitem + # value = stack.pop() + # IndexError: pop from empty list + + pickle_str = input_file.read() + reply = pickle.loads(pickle_str) output_file.close() input_file.close() |