Skip to content

Commit 89669ff

Browse files
corona10vstinner
authored andcommitted
bpo-35283: Add deprecation warning for Thread.isAlive (GH-11454)
Add a deprecated warning for the threading.Thread.isAlive() method.
1 parent 97e1299 commit 89669ff

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

Doc/whatsnew/3.8.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ Deprecated
394394

395395
(Contributed by Serhiy Storchaka in :issue:`33710`.)
396396

397+
* The :meth:`~threading.Thread.isAlive()` method of :class:`threading.Thread` has been deprecated.
398+
(Contributed by Dong-hee Na in :issue:`35283`.)
397399

398400
API and Feature Removals
399401
========================

Lib/test/support/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,14 +2264,14 @@ def start_threads(threads, unlock=None):
22642264
endtime += 60
22652265
for t in started:
22662266
t.join(max(endtime - time.monotonic(), 0.01))
2267-
started = [t for t in started if t.isAlive()]
2267+
started = [t for t in started if t.is_alive()]
22682268
if not started:
22692269
break
22702270
if verbose:
22712271
print('Unable to join %d threads during a period of '
22722272
'%d minutes' % (len(started), timeout))
22732273
finally:
2274-
started = [t for t in started if t.isAlive()]
2274+
started = [t for t in started if t.is_alive()]
22752275
if started:
22762276
faulthandler.dump_traceback(sys.stdout)
22772277
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(DeprecationWarning, 'use is_alive()'):
419+
t.isAlive()
419420
e = threading.Event()
420421
e.isSet()
421422
threading.activeCount()

Lib/threading.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
DeprecationWarning, 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 deprecated warning for the :meth:`threading.Thread.isAlive` method.
2+
Patch by Dong-hee Na.

0 commit comments

Comments
 (0)