]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35283: Add deprecation warning for Thread.isAlive (GH-11454)
authorDong-hee Na <donghee.na92@gmail.com>
Thu, 17 Jan 2019 12:14:45 +0000 (21:14 +0900)
committerVictor Stinner <vstinner@redhat.com>
Thu, 17 Jan 2019 12:14:45 +0000 (13:14 +0100)
Add a deprecated warning for the threading.Thread.isAlive() method.

Doc/whatsnew/3.8.rst
Lib/test/support/__init__.py
Lib/test/test_threading.py
Lib/threading.py
Misc/NEWS.d/next/Library/2019-01-07-17-17-16.bpo-35283.WClosC.rst [new file with mode: 0644]

index 053fe902c4810dc8317a35a4649cc94321cbd5ba..bf8d8f15434b4856b9e751db1cf82dcc104602a2 100644 (file)
@@ -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
 ========================
index dd1790d592b1aeacb61e3aad0c6955edebe249f2..697182ea775f04eaa360cf47ebf8cdbfcf00451a 100644 (file)
@@ -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))
index 8160a5af0064475e7bab524c5e74d85d595b3204..af2d6b59b971eaf87b23dc42dce43ba477569c75 100644 (file)
@@ -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()
index bb41456fb1410c228fff19667f5351c04304eb22..7bc8a8573c7289abedcc4c8ea82ea034df2ea437 100644 (file)
@@ -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 (file)
index 0000000..7118652
--- /dev/null
@@ -0,0 +1,2 @@
+Add a deprecated warning for the :meth:`threading.Thread.isAlive` method.
+Patch by Dong-hee Na.