summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na92@gmail.com>2019-01-17 12:14:45 (GMT)
committerVictor Stinner <vstinner@redhat.com>2019-01-17 12:14:45 (GMT)
commit89669ffe10a9db6343f6ee42239e412c8ad96bde (patch)
tree5c525e474b70d00eaf8c22fa818a5ab44d446f62
parent97e12996f31f6ada4173e2cd4b6807c98ba379a4 (diff)
downloadcpython-89669ffe10a9db6343f6ee42239e412c8ad96bde.zip
cpython-89669ffe10a9db6343f6ee42239e412c8ad96bde.tar.gz
cpython-89669ffe10a9db6343f6ee42239e412c8ad96bde.tar.bz2
bpo-35283: Add deprecation warning for Thread.isAlive (GH-11454)
Add a deprecated warning for the threading.Thread.isAlive() method.
-rw-r--r--Doc/whatsnew/3.8.rst2
-rw-r--r--Lib/test/support/__init__.py4
-rw-r--r--Lib/test/test_threading.py3
-rw-r--r--Lib/threading.py10
-rw-r--r--Misc/NEWS.d/next/Library/2019-01-07-17-17-16.bpo-35283.WClosC.rst2
5 files changed, 17 insertions, 4 deletions
diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst
index 053fe90..bf8d8f1 100644
--- a/Doc/whatsnew/3.8.rst
+++ b/Doc/whatsnew/3.8.rst
@@ -394,6 +394,8 @@ Deprecated
(Contributed by Serhiy Storchaka in :issue:`33710`.)
+* The :meth:`~threading.Thread.isAlive()` method of :class:`threading.Thread` has been deprecated.
+ (Contributed by Dong-hee Na in :issue:`35283`.)
API and Feature Removals
========================
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index dd1790d..697182e 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2264,14 +2264,14 @@ def start_threads(threads, unlock=None):
endtime += 60
for t in started:
t.join(max(endtime - time.monotonic(), 0.01))
- started = [t for t in started if t.isAlive()]
+ started = [t for t in started if t.is_alive()]
if not started:
break
if verbose:
print('Unable to join %d threads during a period of '
'%d minutes' % (len(started), timeout))
finally:
- started = [t for t in started if t.isAlive()]
+ started = [t for t in started if t.is_alive()]
if started:
faulthandler.dump_traceback(sys.stdout)
raise AssertionError('Unable to join %d threads' % len(started))
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 8160a5a..af2d6b5 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -415,7 +415,8 @@ class ThreadTests(BaseTestCase):
t.setDaemon(True)
t.getName()
t.setName("name")
- t.isAlive()
+ with self.assertWarnsRegex(DeprecationWarning, 'use is_alive()'):
+ t.isAlive()
e = threading.Event()
e.isSet()
threading.activeCount()
diff --git a/Lib/threading.py b/Lib/threading.py
index bb41456..7bc8a85 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -1091,7 +1091,15 @@ class Thread:
self._wait_for_tstate_lock(False)
return not self._is_stopped
- isAlive = is_alive
+ def isAlive(self):
+ """Return whether the thread is alive.
+
+ This method is deprecated, use is_alive() instead.
+ """
+ import warnings
+ warnings.warn('isAlive() is deprecated, use is_alive() instead',
+ DeprecationWarning, stacklevel=2)
+ return self.is_alive()
@property
def daemon(self):
diff --git a/Misc/NEWS.d/next/Library/2019-01-07-17-17-16.bpo-35283.WClosC.rst b/Misc/NEWS.d/next/Library/2019-01-07-17-17-16.bpo-35283.WClosC.rst
new file mode 100644
index 0000000..7118652
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-01-07-17-17-16.bpo-35283.WClosC.rst
@@ -0,0 +1,2 @@
+Add a deprecated warning for the :meth:`threading.Thread.isAlive` method.
+Patch by Dong-hee Na.