Rev 4918: Play around with using os.write() to send data to our pipe. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-partial-writes-496818

John Arbash Meinel john at arbash-meinel.com
Tue Dec 22 20:37:05 GMT 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-partial-writes-496818

------------------------------------------------------------
revno: 4918
revision-id: john at arbash-meinel.com-20091222203649-5iegrdl6zt8pssyl
parent: pqm at pqm.ubuntu.com-20091222051149-713jby9bi05y05gr
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0rc1-partial-writes-496818
timestamp: Tue 2009-12-22 14:36:49 -0600
message:
  Play around with using os.write() to send data to our pipe.
-------------- next part --------------
=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py	2009-12-21 17:00:29 +0000
+++ b/bzrlib/smart/medium.py	2009-12-22 20:36:49 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006 Canonical Ltd
+# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -354,7 +354,27 @@
         self.finished = True
 
     def _write_out(self, bytes):
-        osutils.until_no_eintr(self._out.write, bytes)
+        fileno = getattr(self._out, 'fileno', None)
+        if fileno is not None:
+            fileno = fileno()
+        if False and fileno is not None:
+            # We have a valid fileno to write to, use os.write
+            # We get a chance to get interrupted, and still resume the write.
+            # The python wrapper for fwrite() does not allow us to interrupt,
+            # or to determine how many bytes actually got written.
+            while bytes:
+                try:
+                    num_written = os.write(fileno, bytes)
+                except (IOError, OSError), e:
+                    if e.errno == errno.ENOENT:
+                        continue
+                    raise
+                sys.stderr.write('wrote %d bytes\n' % (num_written,))
+                sys.stderr.flush()
+                bytes = bytes[num_written:]
+        else:
+            sys.stderr.write('Writing bulk %d bytes\n' % (len(bytes),))
+            osutils.until_no_eintr(self._out.write, bytes)
 
 
 class SmartClientMediumRequest(object):



More information about the bazaar-commits mailing list