mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
remove py3k warnings about the threading api; update docs
Reviewer: Benjamin Peterson
This commit is contained in:
parent
057dfddc88
commit
973e6c2cf3
4 changed files with 29 additions and 71 deletions
|
|
@ -14,11 +14,12 @@ The :mod:`dummy_threading` module is provided for situations where
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
Some ``camelCase`` names have been converted to their underscored
|
Starting with Python 2.6, this module provides PEP 8 compliant aliases and
|
||||||
equivalents. Others have been replaced by properties. Using the old methods
|
properties to replace the ``camelCase`` names that were inspired by Java's
|
||||||
in 2.6 will trigger a :exc:`DeprecationWarning` when Python is run with the
|
threading API. This updated API is compatible with that of the
|
||||||
:option:`-3` flag and a full :exc:`DeprecationWarning` in 3.0. The old names
|
:mod:`multiprocessing` module. However, no schedule has been set for the
|
||||||
will be removed early in the 3.x series.
|
deprecation of the ``camelCase`` names and they remain fully supported in
|
||||||
|
both Python 2.x and 3.x.
|
||||||
|
|
||||||
This module defines the following functions and objects:
|
This module defines the following functions and objects:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -272,41 +272,6 @@ class TestPy3KWarnings(unittest.TestCase):
|
||||||
def __hash__(self): pass
|
def __hash__(self): pass
|
||||||
self.assertEqual(len(w.warnings), 0)
|
self.assertEqual(len(w.warnings), 0)
|
||||||
|
|
||||||
def test_pep8ified_threading(self):
|
|
||||||
import threading
|
|
||||||
|
|
||||||
t = threading.Thread()
|
|
||||||
with catch_warning() as w:
|
|
||||||
msg = "isDaemon() is deprecated in favor of the " \
|
|
||||||
"Thread.daemon property"
|
|
||||||
self.assertWarning(t.isDaemon(), w, msg)
|
|
||||||
w.reset()
|
|
||||||
msg = "setDaemon() is deprecated in favor of the " \
|
|
||||||
"Thread.daemon property"
|
|
||||||
self.assertWarning(t.setDaemon(True), w, msg)
|
|
||||||
w.reset()
|
|
||||||
msg = "getName() is deprecated in favor of the " \
|
|
||||||
"Thread.name property"
|
|
||||||
self.assertWarning(t.getName(), w, msg)
|
|
||||||
w.reset()
|
|
||||||
msg = "setName() is deprecated in favor of the " \
|
|
||||||
"Thread.name property"
|
|
||||||
self.assertWarning(t.setName("name"), w, msg)
|
|
||||||
w.reset()
|
|
||||||
msg = "isAlive() is deprecated in favor of is_alive()"
|
|
||||||
self.assertWarning(t.isAlive(), w, msg)
|
|
||||||
w.reset()
|
|
||||||
e = threading.Event()
|
|
||||||
msg = "isSet() is deprecated in favor of is_set()"
|
|
||||||
self.assertWarning(e.isSet(), w, msg)
|
|
||||||
w.reset()
|
|
||||||
msg = "currentThread() is deprecated in favor of current_thread()"
|
|
||||||
self.assertWarning(threading.currentThread(), w, msg)
|
|
||||||
w.reset()
|
|
||||||
msg = "activeCount() is deprecated in favor of active_count()"
|
|
||||||
self.assertWarning(threading.activeCount(), w, msg)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TestStdlibRemovals(unittest.TestCase):
|
class TestStdlibRemovals(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,17 @@ from time import time as _time, sleep as _sleep
|
||||||
from traceback import format_exc as _format_exc
|
from traceback import format_exc as _format_exc
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
|
# Note regarding PEP 8 compliant aliases
|
||||||
|
# This threading model was originally inspired by Java, and inherited
|
||||||
|
# the convention of camelCase function and method names from that
|
||||||
|
# language. While those names are not in any imminent danger of being
|
||||||
|
# deprecated, starting with Python 2.6, the module now provides a
|
||||||
|
# PEP 8 compliant alias for any such method name.
|
||||||
|
# Using the new PEP 8 compliant names also facilitates substitution
|
||||||
|
# with the multiprocessing module, which doesn't provide the old
|
||||||
|
# Java inspired names.
|
||||||
|
|
||||||
|
|
||||||
# Rename some stuff so "from threading import *" is safe
|
# Rename some stuff so "from threading import *" is safe
|
||||||
__all__ = ['activeCount', 'active_count', 'Condition', 'currentThread',
|
__all__ = ['activeCount', 'active_count', 'Condition', 'currentThread',
|
||||||
'current_thread', 'enumerate', 'Event',
|
'current_thread', 'enumerate', 'Event',
|
||||||
|
|
@ -33,19 +44,6 @@ del thread
|
||||||
warnings.filterwarnings('ignore', category=DeprecationWarning,
|
warnings.filterwarnings('ignore', category=DeprecationWarning,
|
||||||
module='threading', message='sys.exc_clear')
|
module='threading', message='sys.exc_clear')
|
||||||
|
|
||||||
|
|
||||||
def _old_api(callable, old_name):
|
|
||||||
if not _sys.py3kwarning:
|
|
||||||
return callable
|
|
||||||
@wraps(callable)
|
|
||||||
def old(*args, **kwargs):
|
|
||||||
warnings.warnpy3k("{0}() is deprecated in favor of {1}()"
|
|
||||||
.format(old_name, callable.__name__),
|
|
||||||
stacklevel=3)
|
|
||||||
return callable(*args, **kwargs)
|
|
||||||
old.__name__ = old_name
|
|
||||||
return old
|
|
||||||
|
|
||||||
# Debug support (adapted from ihooks.py).
|
# Debug support (adapted from ihooks.py).
|
||||||
# All the major classes here derive from _Verbose. We force that to
|
# All the major classes here derive from _Verbose. We force that to
|
||||||
# be a new-style class so that all the major classes here are new-style.
|
# be a new-style class so that all the major classes here are new-style.
|
||||||
|
|
@ -287,10 +285,10 @@ class _Condition(_Verbose):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def notify_all(self):
|
def notifyAll(self):
|
||||||
self.notify(len(self.__waiters))
|
self.notify(len(self.__waiters))
|
||||||
|
|
||||||
notifyAll = _old_api(notify_all, "notifyAll")
|
notify_all = notifyAll
|
||||||
|
|
||||||
|
|
||||||
def Semaphore(*args, **kwargs):
|
def Semaphore(*args, **kwargs):
|
||||||
|
|
@ -368,10 +366,10 @@ class _Event(_Verbose):
|
||||||
self.__cond = Condition(Lock())
|
self.__cond = Condition(Lock())
|
||||||
self.__flag = False
|
self.__flag = False
|
||||||
|
|
||||||
def is_set(self):
|
def isSet(self):
|
||||||
return self.__flag
|
return self.__flag
|
||||||
|
|
||||||
isSet = _old_api(is_set, "isSet")
|
is_set = isSet
|
||||||
|
|
||||||
def set(self):
|
def set(self):
|
||||||
self.__cond.acquire()
|
self.__cond.acquire()
|
||||||
|
|
@ -666,11 +664,11 @@ class Thread(_Verbose):
|
||||||
assert self.__initialized, "Thread.__init__() not called"
|
assert self.__initialized, "Thread.__init__() not called"
|
||||||
return self.__ident
|
return self.__ident
|
||||||
|
|
||||||
def is_alive(self):
|
def isAlive(self):
|
||||||
assert self.__initialized, "Thread.__init__() not called"
|
assert self.__initialized, "Thread.__init__() not called"
|
||||||
return self.__started.is_set() and not self.__stopped
|
return self.__started.is_set() and not self.__stopped
|
||||||
|
|
||||||
isAlive = _old_api(is_alive, "isAlive")
|
is_alive = isAlive
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def daemon(self):
|
def daemon(self):
|
||||||
|
|
@ -686,23 +684,15 @@ class Thread(_Verbose):
|
||||||
self.__daemonic = daemonic
|
self.__daemonic = daemonic
|
||||||
|
|
||||||
def isDaemon(self):
|
def isDaemon(self):
|
||||||
warnings.warnpy3k("isDaemon() is deprecated in favor of the " \
|
|
||||||
"Thread.daemon property")
|
|
||||||
return self.daemon
|
return self.daemon
|
||||||
|
|
||||||
def setDaemon(self, daemonic):
|
def setDaemon(self, daemonic):
|
||||||
warnings.warnpy3k("setDaemon() is deprecated in favor of the " \
|
|
||||||
"Thread.daemon property")
|
|
||||||
self.daemon = daemonic
|
self.daemon = daemonic
|
||||||
|
|
||||||
def getName(self):
|
def getName(self):
|
||||||
warnings.warnpy3k("getName() is deprecated in favor of the " \
|
|
||||||
"Thread.name property")
|
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def setName(self, name):
|
def setName(self, name):
|
||||||
warnings.warnpy3k("setName() is deprecated in favor of the " \
|
|
||||||
"Thread.name property")
|
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
# The timer class was contributed by Itamar Shtull-Trauring
|
# The timer class was contributed by Itamar Shtull-Trauring
|
||||||
|
|
@ -803,22 +793,22 @@ class _DummyThread(Thread):
|
||||||
|
|
||||||
# Global API functions
|
# Global API functions
|
||||||
|
|
||||||
def current_thread():
|
def currentThread():
|
||||||
try:
|
try:
|
||||||
return _active[_get_ident()]
|
return _active[_get_ident()]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
##print "current_thread(): no current thread for", _get_ident()
|
##print "current_thread(): no current thread for", _get_ident()
|
||||||
return _DummyThread()
|
return _DummyThread()
|
||||||
|
|
||||||
currentThread = _old_api(current_thread, "currentThread")
|
current_thread = currentThread
|
||||||
|
|
||||||
def active_count():
|
def activeCount():
|
||||||
_active_limbo_lock.acquire()
|
_active_limbo_lock.acquire()
|
||||||
count = len(_active) + len(_limbo)
|
count = len(_active) + len(_limbo)
|
||||||
_active_limbo_lock.release()
|
_active_limbo_lock.release()
|
||||||
return count
|
return count
|
||||||
|
|
||||||
activeCount = _old_api(active_count, "activeCount")
|
active_count = activeCount
|
||||||
|
|
||||||
def enumerate():
|
def enumerate():
|
||||||
_active_limbo_lock.acquire()
|
_active_limbo_lock.acquire()
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,8 @@ C-API
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- The deprecation warnings for the old camelCase threading API were removed.
|
||||||
|
|
||||||
- logging: fixed lack of use of encoding attribute specified on a stream.
|
- logging: fixed lack of use of encoding attribute specified on a stream.
|
||||||
|
|
||||||
- Silenced a trivial compiler warning in the sqlite module.
|
- Silenced a trivial compiler warning in the sqlite module.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue