Skip to content

Commit c2647f2

Browse files
corona10vstinner
authored andcommitted
bpo-35283: Add pending deprecation warning for Thread.isAlive (GH-11604)
Add a pending deprecated warning for the threading.Thread.isAlive() method.
1 parent 5f9a168 commit c2647f2

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

Lib/test/support/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,14 +2224,14 @@ def start_threads(threads, unlock=None):
22242224
endtime += 60
22252225
for t in started:
22262226
t.join(max(endtime - time.monotonic(), 0.01))
2227-
started = [t for t in started if t.isAlive()]
2227+
started = [t for t in started if t.is_alive()]
22282228
if not started:
22292229
break
22302230
if verbose:
22312231
print('Unable to join %d threads during a period of '
22322232
'%d minutes' % (len(started), timeout))
22332233
finally:
2234-
started = [t for t in started if t.isAlive()]
2234+
started = [t for t in started if t.is_alive()]
22352235
if started:
22362236
faulthandler.dump_traceback(sys.stdout)
22372237
raise AssertionError('Unable to join %d threads' % len(started))

Lib/test/test_threading.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ def test_old_threading_api(self):
415415
t.setDaemon(True)
416416
t.getName()
417417
t.setName("name")
418-
t.isAlive()
418+
with self.assertWarnsRegex(PendingDeprecationWarning, 'use is_alive()'):
419+
t.isAlive()
419420
e = threading.Event()
420421
e.isSet()
421422
threading.activeCount()

Lib/threading.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ def join(self, timeout=None):
10071007
When the timeout argument is present and not None, it should be a
10081008
floating point number specifying a timeout for the operation in seconds
10091009
(or fractions thereof). As join() always returns None, you must call
1010-
isAlive() after join() to decide whether a timeout happened -- if the
1010+
is_alive() after join() to decide whether a timeout happened -- if the
10111011
thread is still alive, the join() call timed out.
10121012
10131013
When the timeout argument is not present or None, the operation will
@@ -1091,7 +1091,15 @@ def is_alive(self):
10911091
self._wait_for_tstate_lock(False)
10921092
return not self._is_stopped
10931093

1094-
isAlive = is_alive
1094+
def isAlive(self):
1095+
"""Return whether the thread is alive.
1096+
1097+
This method is deprecated, use is_alive() instead.
1098+
"""
1099+
import warnings
1100+
warnings.warn('isAlive() is deprecated, use is_alive() instead',
1101+
PendingDeprecationWarning, stacklevel=2)
1102+
return self.is_alive()
10951103

10961104
@property
10971105
def daemon(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add a pending deprecated warning for the :meth:`threading.Thread.isAlive` method.
2+
Patch by Dong-hee Na.

0 commit comments

Comments
 (0)