summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py70
1 files changed, 35 insertions, 35 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index bce291e..934eeae 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -8,7 +8,7 @@ from traceback import format_exc as _format_exc
from collections import deque
# Rename some stuff so "from threading import *" is safe
-__all__ = ['activeCount', 'Condition', 'currentThread', 'enumerate', 'Event',
+__all__ = ['active_count', 'Condition', 'current_thread', 'enumerate', 'Event',
'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Thread',
'Timer', 'setprofile', 'settrace', 'local', 'stack_size']
@@ -40,7 +40,7 @@ if __debug__:
if self._verbose:
format = format % args
format = "%s: %s\n" % (
- currentThread().getName(), format)
+ current_thread().get_name(), format)
_sys.stderr.write(format)
else:
@@ -83,11 +83,11 @@ class _RLock(_Verbose):
owner = self._owner
return "<%s(%s, %d)>" % (
self.__class__.__name__,
- owner and owner.getName(),
+ owner and owner.get_name(),
self._count)
def acquire(self, blocking=1):
- me = currentThread()
+ me = current_thread()
if self._owner is me:
self._count = self._count + 1
if __debug__:
@@ -107,7 +107,7 @@ class _RLock(_Verbose):
__enter__ = acquire
def release(self):
- if self._owner is not currentThread():
+ if self._owner is not current_thread():
raise RuntimeError("cannot release un-aquired lock")
self._count = count = self._count - 1
if not count:
@@ -141,7 +141,7 @@ class _RLock(_Verbose):
return (count, owner)
def _is_owned(self):
- return self._owner is currentThread()
+ return self._owner is current_thread()
def Condition(*args, **kwargs):
@@ -190,7 +190,7 @@ class _Condition(_Verbose):
self._lock.acquire() # Ignore saved state
def _is_owned(self):
- # Return True if lock is owned by currentThread.
+ # Return True if lock is owned by current_thread.
# This method is called only if __lock doesn't have _is_owned().
if self._lock.acquire(0):
self._lock.release()
@@ -258,7 +258,7 @@ class _Condition(_Verbose):
except ValueError:
pass
- def notifyAll(self):
+ def notify_all(self):
self.notify(len(self._waiters))
@@ -337,14 +337,14 @@ class _Event(_Verbose):
self._cond = Condition(Lock())
self._flag = False
- def isSet(self):
+ def is_set(self):
return self._flag
def set(self):
self._cond.acquire()
try:
self._flag = True
- self._cond.notifyAll()
+ self._cond.notify_all()
finally:
self._cond.release()
@@ -412,12 +412,12 @@ class Thread(_Verbose):
def _set_daemon(self):
# Overridden in _MainThread and _DummyThread
- return currentThread().isDaemon()
+ return current_thread().is_daemon()
def __repr__(self):
assert self._initialized, "Thread.__init__() was not called"
status = "initial"
- if self._started.isSet():
+ if self._started.is_set():
status = "started"
if self._stopped:
status = "stopped"
@@ -431,7 +431,7 @@ class Thread(_Verbose):
if not self._initialized:
raise RuntimeError("thread.__init__() not called")
- if self._started.isSet():
+ if self._started.is_set():
raise RuntimeError("thread already started")
if __debug__:
self._note("%s.start(): starting thread", self)
@@ -502,7 +502,7 @@ class Thread(_Verbose):
# self.
if _sys:
_sys.stderr.write("Exception in thread %s:\n%s\n" %
- (self.getName(), _format_exc()))
+ (self.get_name(), _format_exc()))
else:
# Do the best job possible w/o a huge amt. of code to
# approximate a traceback (code ideas from
@@ -510,7 +510,7 @@ class Thread(_Verbose):
exc_type, exc_value, exc_tb = self._exc_info()
try:
print((
- "Exception in thread " + self.getName() +
+ "Exception in thread " + self.get_name() +
" (most likely raised during interpreter shutdown):"), file=self._stderr)
print((
"Traceback (most recent call last):"), file=self._stderr)
@@ -549,7 +549,7 @@ class Thread(_Verbose):
def _stop(self):
self._block.acquire()
self._stopped = True
- self._block.notifyAll()
+ self._block.notify_all()
self._block.release()
def _delete(self):
@@ -582,7 +582,7 @@ class Thread(_Verbose):
# There must not be any python code between the previous line
# and after the lock is released. Otherwise a tracing function
# could try to acquire the lock again in the same thread, (in
- # currentThread()), and would block.
+ # current_thread()), and would block.
except KeyError:
if 'dummy_threading' not in _sys.modules:
raise
@@ -590,9 +590,9 @@ class Thread(_Verbose):
def join(self, timeout=None):
if not self._initialized:
raise RuntimeError("Thread.__init__() not called")
- if not self._started.isSet():
+ if not self._started.is_set():
raise RuntimeError("cannot join thread before it is started")
- if self is currentThread():
+ if self is current_thread():
raise RuntimeError("cannot join current thread")
if __debug__:
@@ -621,30 +621,30 @@ class Thread(_Verbose):
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):
+ def set_name(self, name):
assert self._initialized, "Thread.__init__() not called"
self._name = str(name)
- def getIdent(self):
+ def get_ident(self):
assert self._initialized, "Thread.__init__() not called"
return self._ident
- def isAlive(self):
+ def is_alive(self):
assert self._initialized, "Thread.__init__() not called"
- return self._started.isSet() and not self._stopped
+ return self._started.is_set() and not self._stopped
- def isDaemon(self):
+ def is_daemon(self):
assert self._initialized, "Thread.__init__() not called"
return self._daemonic
- def setDaemon(self, daemonic):
+ def set_daemon(self, daemonic):
if not self._initialized:
raise RuntimeError("Thread.__init__() not called")
- if self._started.isSet():
+ if self._started.is_set():
raise RuntimeError("cannot set daemon status of active thread");
self._daemonic = daemonic
@@ -675,7 +675,7 @@ class _Timer(Thread):
def run(self):
self.finished.wait(self.interval)
- if not self.finished.isSet():
+ if not self.finished.is_set():
self.function(*self.args, **self.kwargs)
self.finished.set()
@@ -709,16 +709,16 @@ class _MainThread(Thread):
def _pickSomeNonDaemonThread():
for t in enumerate():
- if not t.isDaemon() and t.isAlive():
+ if not t.is_daemon() and t.is_alive():
return t
return None
# Dummy thread class to represent threads not started here.
# These aren't garbage collected when they die, nor can they be waited for.
-# If they invoke anything in threading.py that calls currentThread(), they
+# If they invoke anything in threading.py that calls current_thread(), they
# leave an entry in the _active dict forever after.
-# Their purpose is to return *something* from currentThread().
+# Their purpose is to return *something* from current_thread().
# They are marked as daemon threads so we won't wait for them
# when we exit (conform previous semantics).
@@ -747,14 +747,14 @@ class _DummyThread(Thread):
# Global API functions
-def currentThread():
+def current_thread():
try:
return _active[_get_ident()]
except KeyError:
- ##print "currentThread(): no current thread for", _get_ident()
+ ##print "current_thread(): no current thread for", _get_ident()
return _DummyThread()
-def activeCount():
+def active_count():
_active_limbo_lock.acquire()
count = len(_active) + len(_limbo)
_active_limbo_lock.release()
@@ -831,7 +831,7 @@ def _test():
counter = 0
while counter < self.quota:
counter = counter + 1
- self.queue.put("%s.%d" % (self.getName(), counter))
+ self.queue.put("%s.%d" % (self.get_name(), counter))
_sleep(random() * 0.00001)