Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3085c9

Browse files
committed
remove the deprecation warnings for the old threading API; update the docs
Reviewer: Benjamin Peterson
1 parent f82b856 commit b3085c9

4 files changed

Lines changed: 33 additions & 66 deletions

File tree

Doc/library/threading.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ The :mod:`dummy_threading` module is provided for situations where
1414

1515
.. note::
1616

17-
Some ``camelCase`` names have been converted to their underscored
18-
equivalents. Others have been replaced by properties. Using the old methods
19-
in 2.6 will trigger a :exc:`DeprecationWarning` when Python is run with the
20-
:option:`-3` flag and a full :exc:`DeprecationWarning` in 3.0. The old names
21-
will be removed early in the 3.x series.
17+
While they are not listed below, the ``camelCase`` names used for some
18+
methods and functions in this module in the Python 2.x series are still
19+
supported by this module.
2220

2321
This module defines the following functions and objects:
2422

Lib/test/test_threading.py

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -323,44 +323,18 @@ def _run(self, other_ref, yet_another):
323323
msg=('%d references still around' %
324324
sys.getrefcount(weak_raising_cyclic_object())))
325325

326-
def test_pep8ified_threading(self):
327-
def check(_, w, msg):
328-
self.assertEqual(str(w.message), msg)
329-
326+
def test_old_threading_api(self):
327+
# Just a quick sanity check to make sure the old method names are
328+
# still present
330329
t = threading.Thread()
331-
with catch_warning() as w:
332-
try:
333-
del threading.__warningregistry__
334-
except AttributeError:
335-
pass
336-
msg = "isDaemon() is deprecated in favor of the " \
337-
"Thread.daemon property"
338-
check(t.isDaemon(), w, msg)
339-
w.reset()
340-
msg = "setDaemon() is deprecated in favor of the " \
341-
"Thread.daemon property"
342-
check(t.setDaemon(True), w, msg)
343-
w.reset()
344-
msg = "getName() is deprecated in favor of the " \
345-
"Thread.name property"
346-
check(t.getName(), w, msg)
347-
w.reset()
348-
msg = "setName() is deprecated in favor of the " \
349-
"Thread.name property"
350-
check(t.setName("name"), w, msg)
351-
w.reset()
352-
msg = "isAlive() is deprecated in favor of is_alive()"
353-
check(t.isAlive(), w, msg)
354-
w.reset()
355-
e = threading.Event()
356-
msg = "isSet() is deprecated in favor of is_set()"
357-
check(e.isSet(), w, msg)
358-
w.reset()
359-
msg = "currentThread() is deprecated in favor of current_thread()"
360-
check(threading.currentThread(), w, msg)
361-
w.reset()
362-
msg = "activeCount() is deprecated in favor of active_count()"
363-
check(threading.activeCount(), w, msg)
330+
t.isDaemon()
331+
t.setDaemon(True)
332+
t.getName()
333+
t.setName("name")
334+
t.isAlive()
335+
e = threading.Event()
336+
e.isSet()
337+
threading.activeCount()
364338

365339

366340
class ThreadJoinOnShutdown(unittest.TestCase):

Lib/threading.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22

33
import sys as _sys
44
import _thread
5-
import warnings
65

76
from time import time as _time, sleep as _sleep
87
from traceback import format_exc as _format_exc
98
from collections import deque
109

10+
# Note regarding PEP 8 compliant names
11+
# This threading model was originally inspired by Java, and inherited
12+
# the convention of camelCase function and method names from that
13+
# language. Those originaly names are not in any imminent danger of
14+
# being deprecated (even for Py3k),so this module provides them as an
15+
# alias for the PEP 8 compliant names
16+
# Note that using the new PEP 8 compliant names facilitates substitution
17+
# with the multiprocessing module, which doesn't provide the old
18+
# Java inspired names.
19+
20+
1121
# Rename some stuff so "from threading import *" is safe
1222
__all__ = ['active_count', 'Condition', 'current_thread', 'enumerate', 'Event',
1323
'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Thread',
@@ -262,6 +272,8 @@ def notify(self, n=1):
262272
def notify_all(self):
263273
self.notify(len(self._waiters))
264274

275+
notifyAll = notify_all
276+
265277

266278
def Semaphore(*args, **kwargs):
267279
return _Semaphore(*args, **kwargs)
@@ -341,10 +353,7 @@ def __init__(self, verbose=None):
341353
def is_set(self):
342354
return self._flag
343355

344-
def isSet(self):
345-
warnings.warn("isSet() is deprecated in favor of is_set()",
346-
DeprecationWarning)
347-
return self.is_set()
356+
isSet = is_set
348357

349358
def set(self):
350359
self._cond.acquire()
@@ -646,10 +655,7 @@ def is_alive(self):
646655
assert self._initialized, "Thread.__init__() not called"
647656
return self._started.is_set() and not self._stopped
648657

649-
def isAlive(self):
650-
warnings.warn("isAlive() is deprecated in favor of is_alive()",
651-
DeprecationWarning)
652-
return self.is_alive()
658+
isAlive = is_alive
653659

654660
@property
655661
def daemon(self):
@@ -665,23 +671,15 @@ def daemon(self, daemonic):
665671
self._daemonic = daemonic
666672

667673
def isDaemon(self):
668-
warnings.warn("isDaemon() is deprecated in favor of the " \
669-
"Thread.daemon property", DeprecationWarning)
670674
return self.daemon
671675

672676
def setDaemon(self, daemonic):
673-
warnings.warn("setDaemon() is deprecated in favor of the " \
674-
"Thread.daemon property", DeprecationWarning)
675677
self.daemon = daemonic
676678

677679
def getName(self):
678-
warnings.warn("getName() is deprecated in favor of the " \
679-
"Thread.name property", DeprecationWarning)
680680
return self.name
681681

682682
def setName(self, name):
683-
warnings.warn("setName() is deprecated in favor of the " \
684-
"Thread.name property", DeprecationWarning)
685683
self.name = name
686684

687685
# The timer class was contributed by Itamar Shtull-Trauring
@@ -790,20 +788,15 @@ def current_thread():
790788
##print "current_thread(): no current thread for", _get_ident()
791789
return _DummyThread()
792790

793-
def currentThread():
794-
warnings.warn("currentThread() is deprecated in favor of current_thread()",
795-
DeprecationWarning)
791+
currentThread = current_thread
796792

797793
def active_count():
798794
_active_limbo_lock.acquire()
799795
count = len(_active) + len(_limbo)
800796
_active_limbo_lock.release()
801797
return count
802798

803-
def activeCount():
804-
warnings.warn("activeCount() is deprecated in favor of active_count()",
805-
DeprecationWarning)
806-
return active_count()
799+
activeCount = active_count
807800

808801
def enumerate():
809802
_active_limbo_lock.acquire()

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ C API
6060
Library
6161
-------
6262

63+
- The deprecation warnings for the camelCase threading API names were removed.
64+
6365
Extension Modules
6466
-----------------
6567

0 commit comments

Comments
 (0)