[Python-checkins] bpo-35283: Add pending deprecation warning for Thread.isAlive (GH-11604)

Victor Stinner webhook-mailer at python.org
Fri Jan 18 09:09:49 EST 2019


https://github.com/python/cpython/commit/c2647f2e45d2741fc44fd621966e05d15f2cd26a
commit: c2647f2e45d2741fc44fd621966e05d15f2cd26a
branch: 3.7
author: Dong-hee Na <donghee.na92 at gmail.com>
committer: Victor Stinner <vstinner at redhat.com>
date: 2019-01-18T15:09:43+01:00
summary:

bpo-35283: Add pending deprecation warning for Thread.isAlive (GH-11604)

Add a pending deprecated warning for the threading.Thread.isAlive() method.

files:
A Misc/NEWS.d/next/Library/2019-01-07-17-17-16.bpo-35283.WClosC.rst
M Lib/test/support/__init__.py
M Lib/test/test_threading.py
M Lib/threading.py

diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 25c05edad340..a9cfa2a39540 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2224,14 +2224,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 8160a5af0064..27f328dbe63c 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -415,7 +415,8 @@ def test_old_threading_api(self):
         t.setDaemon(True)
         t.getName()
         t.setName("name")
-        t.isAlive()
+        with self.assertWarnsRegex(PendingDeprecationWarning, 'use is_alive()'):
+            t.isAlive()
         e = threading.Event()
         e.isSet()
         threading.activeCount()
diff --git a/Lib/threading.py b/Lib/threading.py
index bb41456fb141..f260a7cceca4 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -1007,7 +1007,7 @@ def join(self, timeout=None):
         When the timeout argument is present and not None, it should be a
         floating point number specifying a timeout for the operation in seconds
         (or fractions thereof). As join() always returns None, you must call
-        isAlive() after join() to decide whether a timeout happened -- if the
+        is_alive() after join() to decide whether a timeout happened -- if the
         thread is still alive, the join() call timed out.
 
         When the timeout argument is not present or None, the operation will
@@ -1091,7 +1091,15 @@ def is_alive(self):
         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',
+                      PendingDeprecationWarning, 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 000000000000..99544f4cf4ff
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-01-07-17-17-16.bpo-35283.WClosC.rst
@@ -0,0 +1,2 @@
+Add a pending deprecated warning for the :meth:`threading.Thread.isAlive` method.
+Patch by Dong-hee Na.



More information about the Python-checkins mailing list