Add snake-case function names for 'threading2'-module

Closes: #165
This commit is contained in:
kamgha 2017-08-26 03:54:29 +02:00 committed by rdb
parent bbdc5d2341
commit b9437316b4

View File

@ -24,9 +24,18 @@ from time import time as _time
from traceback import format_exc as _format_exc from traceback import format_exc as _format_exc
# Rename some stuff so "from threading import *" is safe # Rename some stuff so "from threading import *" is safe
__all__ = ['activeCount', 'Condition', 'currentThread', 'enumerate', 'Event', __all__ = [
'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Thread', 'enumerate', 'active_count', 'activeCount',
'Timer', 'setprofile', 'settrace', 'local', 'stack_size'] 'Condition',
'current_thread', 'currentThread',
'Event',
'Lock', 'RLock',
'Semaphore', 'BoundedSemaphore',
'Thread',
'Timer',
'local',
'setprofile', 'settrace', 'stack_size'
]
_start_new_thread = thread.start_new_thread _start_new_thread = thread.start_new_thread
_allocate_lock = thread.allocate_lock _allocate_lock = thread.allocate_lock
@ -581,10 +590,12 @@ class Thread(_Verbose):
assert self.__initialized, "Thread.__init__() not called" assert self.__initialized, "Thread.__init__() not called"
self.__name = str(name) self.__name = str(name)
def isAlive(self): def is_alive(self):
assert self.__initialized, "Thread.__init__() not called" assert self.__initialized, "Thread.__init__() not called"
return self.__started and not self.__stopped return self.__started and not self.__stopped
isAlive = is_alive
def isDaemon(self): def isDaemon(self):
assert self.__initialized, "Thread.__init__() not called" assert self.__initialized, "Thread.__init__() not called"
return self.__daemonic return self.__daemonic
@ -692,19 +703,23 @@ class _DummyThread(Thread):
# Global API functions # Global API functions
def currentThread(): def current_thread():
try: try:
return _active[_get_ident()] return _active[_get_ident()]
except KeyError: except KeyError:
##print "currentThread(): no current thread for", _get_ident() ##print "current_thread(): no current thread for", _get_ident()
return _DummyThread() return _DummyThread()
def activeCount(): currentThread = current_thread
def active_count():
_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 = active_count
def enumerate(): def enumerate():
_active_limbo_lock.acquire() _active_limbo_lock.acquire()
active = list(_active.values()) + list(_limbo.values()) active = list(_active.values()) + list(_limbo.values())