Index: ../trunk/Lib/threading.py =================================================================== --- ../trunk/Lib/threading.py (revision 63955) +++ ../trunk/Lib/threading.py (working copy) @@ -12,6 +12,7 @@ from time import time as _time, sleep as _sleep from traceback import format_exc as _format_exc from collections import deque +from functools import wraps # Rename some stuff so "from threading import *" is safe __all__ = ['activeCount', 'Condition', 'currentThread', 'enumerate', 'Event', @@ -31,6 +32,17 @@ module='threading', message='sys.exc_clear') +def _old_api(meth, old_name): + if not _sys.py3kwarning: + return meth + @wraps(meth) + def old(*args, **kwargs): + warnings.warnpy3k("In 3.x, {0} is renamed to {1}" + .format(old_name, meth.__name__)) + meth(*args, **kwargs) + return old + + # Debug support (adapted from ihooks.py). # 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. @@ -271,10 +283,12 @@ except ValueError: pass - def notifyAll(self): + def notify_all(self): self.notify(len(self.__waiters)) + notifyAll = _old_api(notify_all, "notifyAll") + def Semaphore(*args, **kwargs): return _Semaphore(*args, **kwargs) @@ -350,9 +364,11 @@ self.__cond = Condition(Lock()) self.__flag = False - def isSet(self): + def is_set(self): return self.__flag + isSet = _old_api(is_set, "isSet") + def set(self): self.__cond.acquire() try: @@ -631,33 +647,45 @@ finally: self.__block.release() - def getName(self): + def get_name(self): assert self.__initialized, "Thread.__init__() not called" return self.__name - def setName(self, name): + getName = _old_api(get_name, "getName") + + def set_name(self, name): assert self.__initialized, "Thread.__init__() not called" self.__name = str(name) - def getIdent(self): + setName = _old_api(set_name, "setName") + + def get_ident(self): assert self.__initialized, "Thread.__init__() not called" return self.__ident - def isAlive(self): + getIdent = _old_api(get_ident, "getIdent") + + def is_alive(self): assert self.__initialized, "Thread.__init__() not called" return self.__started.isSet() and not self.__stopped - def isDaemon(self): + isAlive = _old_api(is_alive, "isAlive") + + def is_daemon(self): assert self.__initialized, "Thread.__init__() not called" return self.__daemonic - def setDaemon(self, daemonic): + isDaemon = _old_api(is_daemon, "isDaemon") + + def set_daemon(self, daemonic): if not self.__initialized: raise RuntimeError("Thread.__init__() not called") if self.__started.isSet(): raise RuntimeError("cannot set daemon status of active thread"); self.__daemonic = daemonic + setDaemon = _old_api(set_daemon, "setDaemon") + # The timer class was contributed by Itamar Shtull-Trauring def Timer(*args, **kwargs): @@ -756,19 +784,23 @@ # Global API functions -def currentThread(): +def current_thread(): try: return _active[_get_ident()] except KeyError: ##print "currentThread(): no current thread for", _get_ident() return _DummyThread() -def activeCount(): +currentThread = _old_api(current_thread, "currentThread") + +def active_count(): _active_limbo_lock.acquire() count = len(_active) + len(_limbo) _active_limbo_lock.release() return count +activeCount = _old_api(active_count, "activeCount") + def enumerate(): _active_limbo_lock.acquire() active = _active.values() + _limbo.values()