Rev 6195: Add a nicer repr for shutting down. in http://bazaar.launchpad.net/~jameinel/bzr/2.5-soft-hangup-795025
John Arbash Meinel
john at arbash-meinel.com
Fri Sep 23 20:25:01 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.5-soft-hangup-795025
------------------------------------------------------------
revno: 6195
revision-id: john at arbash-meinel.com-20110923202451-5hrc3s8zmmh9tnoi
parent: john at arbash-meinel.com-20110923200950-eps56g6unln7s7qw
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.5-soft-hangup-795025
timestamp: Fri 2011-09-23 22:24:51 +0200
message:
Add a nicer repr for shutting down.
Also, if we disconnect the stdin/stdout handles, it looks like we get ValueError
trying to flush them.
-------------- next part --------------
=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py 2011-09-23 20:09:50 +0000
+++ b/bzrlib/smart/medium.py 2011-09-23 20:24:51 +0000
@@ -360,6 +360,18 @@
timeout=timeout)
sock.setblocking(True)
self.socket = sock
+ # Get the getpeername now, as we might be closed later when we care.
+ try:
+ self._client_info = sock.getpeername()
+ except socket.error:
+ self._client_info = '<unknown>'
+
+ def __str__(self):
+ return '%s(client=%s)' % (self.__class__.__name__, self._client_info)
+
+ def __repr__(self):
+ return '%s.%s(client=%s)' % (self.__module__, self.__class__.__name__,
+ self._client_info)
def _serve_one_request_unguarded(self, protocol):
while protocol.next_read_size():
=== modified file 'bzrlib/tests/test_smart_signals.py'
--- a/bzrlib/tests/test_smart_signals.py 2011-09-23 20:09:50 +0000
+++ b/bzrlib/tests/test_smart_signals.py 2011-09-23 20:24:51 +0000
@@ -184,8 +184,6 @@
v = response_handler.read_body_bytes()
if v != content:
self.fail('Got the wrong content back, expected 1M "a"')
- # writer is closed, so read returns nothing.
- self.assertEqual('', client_read.read())
stopped.wait()
server_thread.join()
=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py 2011-09-23 17:39:14 +0000
+++ b/bzrlib/tests/test_smart_transport.py 2011-09-23 20:24:51 +0000
@@ -1172,8 +1172,8 @@
def test_propagates_timeout(self):
server = _mod_server.SmartTCPServer(None, client_timeout=1.23)
- server_socket = socket.socket()
- handler = server._make_handler(server_socket)
+ server_sock, client_sock = portable_socket_pair()
+ handler = server._make_handler(server_sock)
self.assertEqual(1.23, handler._client_timeout)
def test_serve_conn_tracks_connections(self):
@@ -1280,7 +1280,7 @@
log = self.get_log()
self.assertThat(log, DocTestMatches("""\
INFO Requested to stop gracefully
-... Stopping <bzrlib.smart.medium.SmartServerSocketStreamMedium ...
+... Stopping SmartServerSocketStreamMedium(client=('127.0.0.1', ...
INFO Waiting for 1 client(s) to finish
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
=== modified file 'bzrlib/trace.py'
--- a/bzrlib/trace.py 2011-07-15 14:13:32 +0000
+++ b/bzrlib/trace.py 2011-09-23 20:24:51 +0000
@@ -559,6 +559,10 @@
try:
sys.stdout.flush()
sys.stderr.flush()
+ except ValueError, e:
+ # On Windows, I get ValueError calling stdout.flush() on a closed
+ # handle
+ pass
except IOError, e:
import errno
if e.errno in [errno.EINVAL, errno.EPIPE]:
More information about the bazaar-commits
mailing list