From 881dc7d5ca16897758e28ca10d567bedbe9eb924 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 22 Jan 2019 20:24:48 +0000 Subject: [PATCH] issue #477: more 2.4-compatible thread.get_ident() use. --- mitogen/core.py | 5 +++-- mitogen/parent.py | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mitogen/core.py b/mitogen/core.py index c17b02f7..776699bd 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -2185,7 +2185,7 @@ class Waker(BasicStream): :raises mitogen.core.Error: :meth:`defer` was called after :class:`Broker` has begun shutdown. """ - if threading.currentThread().ident == self.broker_ident: + if thread.get_ident() == self.broker_ident: _vv and IOLOG.debug('%r.defer() [immediate]', self) return func(*args, **kwargs) if self._broker._exitted: @@ -2631,7 +2631,6 @@ class Broker(object): name='mitogen-broker' ) self._thread.start() - self._waker.broker_ident = self._thread.ident def start_receive(self, stream): """ @@ -2766,6 +2765,8 @@ class Broker(object): Broker thread main function. Dispatches IO events until :meth:`shutdown` is called. """ + # For Python 2.4, no way to retrieve ident except on thread. + self._waker.broker_ident = thread.get_ident() try: while self._alive: self._loop_once() diff --git a/mitogen/parent.py b/mitogen/parent.py index fad00b49..8ab12d8b 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -53,6 +53,11 @@ import zlib # Absolute imports for <2.5. select = __import__('select') +try: + import thread +except ImportError: + import threading as thread + import mitogen.core from mitogen.core import b from mitogen.core import LOG @@ -1389,7 +1394,7 @@ class CallChain(object): return '%s-%s-%x-%x' % ( socket.gethostname(), os.getpid(), - threading.currentThread().ident, + thread.get_ident(), int(1e6 * time.time()), )