File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,18 @@ def Popen__terminate(proc):
103103 Popen__terminate = subprocess .Popen .terminate
104104
105105
106+ def threading__thread_is_alive (thread ):
107+ """Return whether the thread is alive (Python version compatibility shim).
108+
109+ On Python >= 3.8 thread.isAlive() is deprecated (removed in Python 3.9).
110+ On Python <= 2.5 thread.is_alive() isn't present (added in Python 2.6).
111+ """
112+ try :
113+ return thread .is_alive ()
114+ except AttributeError :
115+ return thread .isAlive ()
116+
117+
106118def wait_for_port (
107119 host ,
108120 port ,
@@ -334,7 +346,9 @@ def _teardown_check_threads(self):
334346 for thread in threading .enumerate ():
335347 name = thread .getName ()
336348 # Python 2.4: enumerate() may return stopped threads.
337- assert (not thread .isAlive ()) or name in self .ALLOWED_THREADS , \
349+ assert \
350+ not threading__thread_is_alive (thread ) \
351+ or name in self .ALLOWED_THREADS , \
338352 'Found thread %r still running after tests.' % (name ,)
339353 counts [name ] = counts .get (name , 0 ) + 1
340354
Original file line number Diff line number Diff line change @@ -31,14 +31,14 @@ class RunWithRouterTest(testlib.TestCase):
3131 def test_run_with_broker (self ):
3232 router = mitogen .utils .run_with_router (func0 )
3333 self .assertIsInstance (router , mitogen .master .Router )
34- self .assertFalse (router .broker ._thread . isAlive ( ))
34+ self .assertFalse (testlib . threading__thread_is_alive ( router .broker ._thread ))
3535
3636
3737class WithRouterTest (testlib .TestCase ):
3838 def test_with_broker (self ):
3939 router = func ()
4040 self .assertIsInstance (router , mitogen .master .Router )
41- self .assertFalse (router .broker ._thread . isAlive ( ))
41+ self .assertFalse (testlib . threading__thread_is_alive ( router .broker ._thread ))
4242
4343
4444class Dict (dict ): pass
You can’t perform that action at this time.
0 commit comments