Skip to content

Commit 0c87421

Browse files
committed
threading: Deprecated items to be removed in 3.21.
Closes: #154205 Signed-off-by: Jeff Epler <jepler@unpythonic.net>
1 parent 1f9d20b commit 0c87421

4 files changed

Lines changed: 32 additions & 24 deletions

File tree

Doc/deprecations/pending-removal-in-3.21.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@ Pending removal in Python 3.21
2828

2929
* ``tempfile._TemporaryFileWrapper`` will be removed in Python 3.21. Use the
3030
public :class:`tempfile.TemporaryFileWrapper` instead.
31+
32+
* :mod:`threading`:
33+
* ``threading.Condition.notifyAll``, ``threading.Event.isSet``, and
34+
``threading.activeCount`` will be removed in Python 3.21. Use the snake case
35+
names (e.g., ``notify_all``) instead.
36+
* ``threading.Thread.isDaemon``, ``threading.Thread.setDaemon`` will be removed
37+
in Python 3.21. Use the property ``threading.Thread.daemon`` instead.
38+
* ``threading.Thread.getName`` and ``threading.Thread.setName`` will be removed
39+
in Python 3.21. Use the property ``threading.Thread.name`` instead.

Doc/whatsnew/3.16.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,15 @@ New deprecations
720720
Use the new public :class:`tempfile.TemporaryFileWrapper` instead,
721721
which is the return type of :func:`tempfile.NamedTemporaryFile`.
722722

723+
* :mod:`threading`:
724+
* ``threading.Condition.notifyAll``, ``threading.Event.isSet``, and
725+
``threading.activeCount`` will be removed in Python 3.21. Use the snake case
726+
names (e.g., ``notify_all``) instead.
727+
* ``threading.Thread.isDaemon``, ``threading.Thread.setDaemon`` will be removed
728+
in Python 3.21. Use the property ``threading.Thread.daemon`` instead.
729+
* ``threading.Thread.getName`` and ``threading.Thread.setName`` will be removed
730+
in Python 3.21. Use the property ``threading.Thread.name`` instead.
731+
723732
* :mod:`tkinter`:
724733

725734
* :func:`tkinter.filedialog.askopenfiles` is deprecated and slated for

Lib/threading.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys as _sys
55
import _thread
66
import _contextvars
7+
lazy import warnings
78

89
from time import monotonic as _time
910
from _weakrefset import WeakSet
@@ -444,9 +445,7 @@ def notifyAll(self):
444445
This method is deprecated, use notify_all() instead.
445446
446447
"""
447-
import warnings
448-
warnings.warn('notifyAll() is deprecated, use notify_all() instead',
449-
DeprecationWarning, stacklevel=2)
448+
warnings._deprecated("notifyAll", 'notifyAll() is deprecated, use notify_all() instead', remove=(3, 21))
450449
self.notify_all()
451450

452451

@@ -616,9 +615,7 @@ def isSet(self):
616615
This method is deprecated, use is_set() instead.
617616
618617
"""
619-
import warnings
620-
warnings.warn('isSet() is deprecated, use is_set() instead',
621-
DeprecationWarning, stacklevel=2)
618+
warnings._deprecated("isSet", 'isSet() is deprecated, use is_set() instead', remove=(3, 21))
622619
return self.is_set()
623620

624621
def set(self):
@@ -1352,9 +1349,7 @@ def isDaemon(self):
13521349
This method is deprecated, use the daemon attribute instead.
13531350
13541351
"""
1355-
import warnings
1356-
warnings.warn('isDaemon() is deprecated, get the daemon attribute instead',
1357-
DeprecationWarning, stacklevel=2)
1352+
warnings._deprecated('isDaemon', 'isDaemon() is deprecated, get the daemon attribute instead',remove=(3,21))
13581353
return self.daemon
13591354

13601355
def setDaemon(self, daemonic):
@@ -1363,9 +1358,7 @@ def setDaemon(self, daemonic):
13631358
This method is deprecated, use the .daemon property instead.
13641359
13651360
"""
1366-
import warnings
1367-
warnings.warn('setDaemon() is deprecated, set the daemon attribute instead',
1368-
DeprecationWarning, stacklevel=2)
1361+
warnings._deprecated('setDaemon', 'setDaemon() is deprecated, set the daemon attribute instead', remove=(3,21))
13691362
self.daemon = daemonic
13701363

13711364
def getName(self):
@@ -1374,9 +1367,7 @@ def getName(self):
13741367
This method is deprecated, use the name attribute instead.
13751368
13761369
"""
1377-
import warnings
1378-
warnings.warn('getName() is deprecated, get the name attribute instead',
1379-
DeprecationWarning, stacklevel=2)
1370+
warnings._deprecated('getName', 'getName() is deprecated, get the name attribute instead', remove=(3,21))
13801371
return self.name
13811372

13821373
def setName(self, name):
@@ -1385,9 +1376,7 @@ def setName(self, name):
13851376
This method is deprecated, use the name attribute instead.
13861377
13871378
"""
1388-
import warnings
1389-
warnings.warn('setName() is deprecated, set the name attribute instead',
1390-
DeprecationWarning, stacklevel=2)
1379+
warnings._deprecated('setName', 'setName() is deprecated, set the name attribute instead', remove=(3,21))
13911380
self.name = name
13921381

13931382

@@ -1621,9 +1610,7 @@ def currentThread():
16211610
This function is deprecated, use current_thread() instead.
16221611
16231612
"""
1624-
import warnings
1625-
warnings.warn('currentThread() is deprecated, use current_thread() instead',
1626-
DeprecationWarning, stacklevel=2)
1613+
warnings._deprecated('currentThread', 'currentThread() is deprecated, use current_thread() instead', remove=(3,21))
16271614
return current_thread()
16281615

16291616
def active_count():
@@ -1644,9 +1631,7 @@ def activeCount():
16441631
This function is deprecated, use active_count() instead.
16451632
16461633
"""
1647-
import warnings
1648-
warnings.warn('activeCount() is deprecated, use active_count() instead',
1649-
DeprecationWarning, stacklevel=2)
1634+
warnings._deprecated('activeCount', 'activeCount() is deprecated, use active_count() instead', remove=(3,21))
16501635
return active_count()
16511636

16521637
def _enumerate():
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The methods ``threading.Condition.notifyAll``, ``threading.Event.isSet``,
2+
``threading.Thread.isDaemon``, ``threading.Thread.setDaemon``,
3+
``threading.Thread.getName``, ``threading.Thread.setName``, and the function
4+
``threading.activeCount``, which have been deprecated since Python 3.10, are
5+
now scheduled for removal in Python 3.21.

0 commit comments

Comments
 (0)