Skip to content

Commit

Permalink
[3.7] bpo-35283: Add deprecation warning for Thread.isAlive (pythonGH…
Browse files Browse the repository at this point in the history
…-11454)

Add a deprecated warning for the threading.Thread.isAlive() method..
(cherry picked from commit 89669ff)

Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
  • Loading branch information
corona10 committed Jan 18, 2019
1 parent 5f9a168 commit 8a5400a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 9 additions & 1 deletion Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add a pending deprecated warning for the :meth:`threading.Thread.isAlive` method.
Patch by Dong-hee Na.

0 comments on commit 8a5400a

Please sign in to comment.