Rev 4914: Switch to using thread.get_ident() which is available on all python versions. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-thread-get_ident

John Arbash Meinel john at arbash-meinel.com
Mon Dec 21 17:00:36 GMT 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-thread-get_ident

------------------------------------------------------------
revno: 4914
revision-id: john at arbash-meinel.com-20091221170029-ef1zyr07p38p2qz6
parent: pqm at pqm.ubuntu.com-20091221060307-uvja3vdy1o6dzzy0
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0rc1-thread-get_ident
timestamp: Mon 2009-12-21 11:00:29 -0600
message:
  Switch to using thread.get_ident() which is available on all python versions.
-------------- next part --------------
=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py	2009-12-18 22:14:18 +0000
+++ b/bzrlib/smart/medium.py	2009-12-21 17:00:29 +0000
@@ -33,7 +33,7 @@
 from bzrlib.lazy_import import lazy_import
 lazy_import(globals(), """
 import atexit
-import threading
+import thread
 import weakref
 
 from bzrlib import (
@@ -300,10 +300,7 @@
         tstart = osutils.timer_func()
         osutils.send_all(self.socket, bytes, self._report_activity)
         if 'hpss' in debug.debug_flags:
-            cur_thread = threading.currentThread()
-            thread_id = getattr(cur_thread, 'ident', None)
-            if thread_id is None:
-                thread_id = cur_thread.getName()
+            thread_id = thread.get_ident()
             trace.mutter('%12s: [%s] %d bytes to the socket in %.3fs'
                          % ('wrote', thread_id, len(bytes),
                             osutils.timer_func() - tstart))

=== modified file 'bzrlib/smart/protocol.py'
--- a/bzrlib/smart/protocol.py	2009-12-18 22:14:18 +0000
+++ b/bzrlib/smart/protocol.py	2009-12-21 17:00:29 +0000
@@ -22,6 +22,7 @@
 from cStringIO import StringIO
 import struct
 import sys
+import thread
 import threading
 import time
 
@@ -1147,12 +1148,7 @@
         self.response_sent = False
         self._headers = {'Software version': bzrlib.__version__}
         if 'hpss' in debug.debug_flags:
-            # python 2.6 introduced 'ident' as a nice small integer to
-            # represent a thread. But it doesn't exist in 2.4/2.5
-            cur_thread = threading.currentThread()
-            self._thread_id = getattr(cur_thread, 'ident', None)
-            if self._thread_id is None:
-                self._thread_id = cur_thread.getName()
+            self._thread_id = thread.get_ident()
             self._response_start_time = None
 
     def _trace(self, action, message, extra_bytes=None, include_time=False):

=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py	2009-12-18 22:14:18 +0000
+++ b/bzrlib/smart/request.py	2009-12-21 17:00:29 +0000
@@ -32,6 +32,7 @@
 
 
 import tempfile
+import thread
 import threading
 
 from bzrlib import (
@@ -291,10 +292,7 @@
         self._command = None
         if 'hpss' in debug.debug_flags:
             self._request_start_time = osutils.timer_func()
-            cur_thread = threading.currentThread()
-            self._thread_id = getattr(cur_thread, 'ident', None)
-            if self._thread_id is None:
-                self._thread_id = cur_thread.getName()
+            self._thread_id = thread.get_ident()
 
     def _trace(self, action, message, extra_bytes=None, include_time=False):
         # It is a bit of a shame that this functionality overlaps with that of 

=== modified file 'bzrlib/tests/blackbox/test_serve.py'
--- a/bzrlib/tests/blackbox/test_serve.py	2009-12-18 21:54:54 +0000
+++ b/bzrlib/tests/blackbox/test_serve.py	2009-12-21 17:00:29 +0000
@@ -233,7 +233,7 @@
         f = open(log_fname, 'rb')
         content = f.read()
         f.close()
-        self.assertContainsRe(content, 'hpss request: \[')
+        self.assertContainsRe(content, r'hpss request: \[[0-9-]+\]')
 
 
 class TestCmdServeChrooting(TestBzrServeBase):



More information about the bazaar-commits mailing list