mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
bpo-35283: Add deprecation warning for Thread.isAlive (GH-11454)
Add a deprecated warning for the threading.Thread.isAlive() method.
This commit is contained in:
parent
97e12996f3
commit
89669ffe10
5 changed files with 17 additions and 4 deletions
|
@ -394,6 +394,8 @@ Deprecated
|
||||||
|
|
||||||
(Contributed by Serhiy Storchaka in :issue:`33710`.)
|
(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
|
API and Feature Removals
|
||||||
========================
|
========================
|
||||||
|
|
|
@ -2264,14 +2264,14 @@ def start_threads(threads, unlock=None):
|
||||||
endtime += 60
|
endtime += 60
|
||||||
for t in started:
|
for t in started:
|
||||||
t.join(max(endtime - time.monotonic(), 0.01))
|
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:
|
if not started:
|
||||||
break
|
break
|
||||||
if verbose:
|
if verbose:
|
||||||
print('Unable to join %d threads during a period of '
|
print('Unable to join %d threads during a period of '
|
||||||
'%d minutes' % (len(started), timeout))
|
'%d minutes' % (len(started), timeout))
|
||||||
finally:
|
finally:
|
||||||
started = [t for t in started if t.isAlive()]
|
started = [t for t in started if t.is_alive()]
|
||||||
if started:
|
if started:
|
||||||
faulthandler.dump_traceback(sys.stdout)
|
faulthandler.dump_traceback(sys.stdout)
|
||||||
raise AssertionError('Unable to join %d threads' % len(started))
|
raise AssertionError('Unable to join %d threads' % len(started))
|
||||||
|
|
|
@ -415,6 +415,7 @@ class ThreadTests(BaseTestCase):
|
||||||
t.setDaemon(True)
|
t.setDaemon(True)
|
||||||
t.getName()
|
t.getName()
|
||||||
t.setName("name")
|
t.setName("name")
|
||||||
|
with self.assertWarnsRegex(DeprecationWarning, 'use is_alive()'):
|
||||||
t.isAlive()
|
t.isAlive()
|
||||||
e = threading.Event()
|
e = threading.Event()
|
||||||
e.isSet()
|
e.isSet()
|
||||||
|
|
|
@ -1091,7 +1091,15 @@ class Thread:
|
||||||
self._wait_for_tstate_lock(False)
|
self._wait_for_tstate_lock(False)
|
||||||
return not self._is_stopped
|
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
|
@property
|
||||||
def daemon(self):
|
def daemon(self):
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Add a deprecated warning for the :meth:`threading.Thread.isAlive` method.
|
||||||
|
Patch by Dong-hee Na.
|
Loading…
Add table
Add a link
Reference in a new issue