Rev 4737: Fix python-2.4/2.5 compatibility. in file:///home/vila/src/bzr/bugs/392127-thread-leak/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Oct 8 09:55:17 BST 2009


At file:///home/vila/src/bzr/bugs/392127-thread-leak/

------------------------------------------------------------
revno: 4737
revision-id: v.ladeuil+lp at free.fr-20091008085517-gbybgf4dszqq31lj
parent: v.ladeuil+lp at free.fr-20091008085334-zrop9mam5nn6m87h
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 392127-thread-leak
timestamp: Thu 2009-10-08 10:55:17 +0200
message:
  Fix python-2.4/2.5 compatibility.
  
  * bzrlib/tests/test_http.py:
  (RecordingServer.connect_socket): Band aid to work around
  python-2.4 missing socket.create_connection().
  
  * bzrlib/tests/http_server.py:
  (TestingThreadingHTTPServer.process_request_thread): Fix
  python2.5/2.4 compatibility.
-------------- next part --------------
=== modified file 'bzrlib/tests/http_server.py'
--- a/bzrlib/tests/http_server.py	2009-10-08 08:53:34 +0000
+++ b/bzrlib/tests/http_server.py	2009-10-08 08:55:17 +0000
@@ -443,7 +443,7 @@
         self.clients = []
 
     def process_request_thread(self, request, client_address):
-        self.clients.append((request, threading.current_thread()))
+        self.clients.append((request, threading.currentThread()))
         try:
             SocketServer.ThreadingTCPServer.process_request_thread(
                 self, request, client_address)

=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py	2009-10-07 15:17:48 +0000
+++ b/bzrlib/tests/test_http.py	2009-10-08 08:55:17 +0000
@@ -252,11 +252,26 @@
             # The client may have already closed the socket.
             pass
 
+    def connect_socket(self):
+        msg = "getaddrinfo returns an empty list"
+        for res in socket.getaddrinfo(self.host, self.port):
+            af, socktype, proto, canonname, sa = res
+            sock = None
+            try:
+                sock = socket.socket(af, socktype, proto)
+                sock.connect(sa)
+                return sock
+
+            except socket.error, msg:
+                if sock is not None:
+                    sock.close()
+        raise socket.error, msg
+
     def tearDown(self):
         try:
             # Issue a fake connection to wake up the server and allow it to
             # finish quickly
-            fake_conn = socket.create_connection((self.host, self.port))
+            fake_conn = self.connect_socket()
             fake_conn.close()
         except socket.error:
             # We might have already closed it.  We don't care.



More information about the bazaar-commits mailing list