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

Skip to content

Commit 672b803

Browse files
committed
Merged revisions 64125 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r64125 | benjamin.peterson | 2008-06-11 12:27:50 -0500 (Wed, 11 Jun 2008) | 2 lines give the threading API PEP 8 names ........
1 parent 559e5d7 commit 672b803

20 files changed

+126
-131
lines changed

Doc/library/threading.rst

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The :mod:`dummy_threading` module is provided for situations where
1515
This module defines the following functions and objects:
1616

1717

18-
.. function:: activeCount()
18+
.. function:: active_count()
1919

2020
Return the number of :class:`Thread` objects currently alive. The returned
2121
count is equal to the length of the list returned by :func:`enumerate`.
@@ -29,7 +29,7 @@ This module defines the following functions and objects:
2929
thread.
3030

3131

32-
.. function:: currentThread()
32+
.. function:: current_thread()
3333

3434
Return the current :class:`Thread` object, corresponding to the caller's thread
3535
of control. If the caller's thread of control was not created through the
@@ -39,10 +39,10 @@ This module defines the following functions and objects:
3939

4040
.. function:: enumerate()
4141

42-
Return a list of all :class:`Thread` objects currently alive. The list includes
43-
daemonic threads, dummy thread objects created by :func:`currentThread`, and the
44-
main thread. It excludes terminated threads and threads that have not yet been
45-
started.
42+
Return a list of all :class:`Thread` objects currently alive. The list
43+
includes daemonic threads, dummy thread objects created by
44+
:func:`current_thread`, and the main thread. It excludes terminated threads
45+
and threads that have not yet been started.
4646

4747

4848
.. function:: Event()
@@ -387,7 +387,7 @@ needs to wake up one consumer thread.
387387
lock, its caller should.
388388

389389

390-
.. method:: Condition.notifyAll()
390+
.. method:: Condition.notify_all()
391391

392392
Wake up all threads waiting on this condition. This method acts like
393393
:meth:`notify`, but wakes up all waiting threads instead of one. If the calling
@@ -544,12 +544,12 @@ Other threads can call a thread's :meth:`join` method. This blocks the calling
544544
thread until the thread whose :meth:`join` method is called is terminated.
545545

546546
A thread has a name. The name can be passed to the constructor, set with the
547-
:meth:`setName` method, and retrieved with the :meth:`getName` method.
547+
:meth:`set_name` method, and retrieved with the :meth:`get_name` method.
548548

549549
A thread can be flagged as a "daemon thread". The significance of this flag is
550550
that the entire Python program exits when only daemon threads are left. The
551551
initial value is inherited from the creating thread. The flag can be set with
552-
the :meth:`setDaemon` method and retrieved with the :meth:`isDaemon` method.
552+
the :meth:`set_daemon` method and retrieved with the :meth:`is_daemon` method.
553553

554554
There is a "main thread" object; this corresponds to the initial thread of
555555
control in the Python program. It is not a daemon thread.
@@ -629,12 +629,12 @@ impossible to detect the termination of alien threads.
629629
raises the same exception.
630630

631631

632-
.. method:: Thread.getName()
632+
.. method:: Thread.get_name()
633633

634634
Return the thread's name.
635635

636636

637-
.. method:: Thread.setName(name)
637+
.. method:: Thread.set_name(name)
638638

639639
Set the thread's name.
640640

@@ -643,18 +643,16 @@ impossible to detect the termination of alien threads.
643643
constructor.
644644

645645

646-
.. method:: Thread.getIdent()
646+
.. method:: Thread.get_ident()
647647

648648
Return the 'thread identifier' of this thread or None if the thread has not
649-
been started. This is a nonzero integer. See the :mod:`thread` module's
650-
:func:`get_ident()` function. Thread identifiers may be recycled when a
651-
thread exits and another thread is created. The identifier is returned
652-
even after the thread has exited.
649+
been started. This is a nonzero integer. See the :func:`thread.get_ident()`
650+
function. Thread identifiers may be recycled when a thread exits and another
651+
thread is created. The identifier is returned even after the thread has
652+
exited.
653653

654-
.. versionadded:: 2.6
655654

656-
657-
.. method:: Thread.isAlive()
655+
.. method:: Thread.is_alive()
658656

659657
Return whether the thread is alive.
660658

@@ -663,12 +661,12 @@ impossible to detect the termination of alien threads.
663661
returns a list of all alive threads.
664662

665663

666-
.. method:: Thread.isDaemon()
664+
.. method:: Thread.is_daemon()
667665

668666
Return the thread's daemon flag.
669667

670668

671-
.. method:: Thread.setDaemon(daemonic)
669+
.. method:: Thread.set_daemon(daemonic)
672670

673671
Set the thread's daemon flag to the Boolean value *daemonic*. This must be
674672
called before :meth:`start` is called, otherwise :exc:`RuntimeError` is raised.

Lib/_threading_local.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,16 @@ def __new__(cls, *args, **kw):
161161
# __init__ being called, to make sure we don't call it
162162
# again ourselves.
163163
dict = object.__getattribute__(self, '__dict__')
164-
currentThread().__dict__[key] = dict
164+
current_thread().__dict__[key] = dict
165165

166166
return self
167167

168168
def _patch(self):
169169
key = object.__getattribute__(self, '_local__key')
170-
d = currentThread().__dict__.get(key)
170+
d = current_thread().__dict__.get(key)
171171
if d is None:
172172
d = {}
173-
currentThread().__dict__[key] = d
173+
current_thread().__dict__[key] = d
174174
object.__setattr__(self, '__dict__', d)
175175

176176
# we have a new instance dict, so call out __init__ if we have
@@ -237,4 +237,4 @@ def __del__(self):
237237
except KeyError:
238238
pass # didn't have anything in this thread
239239

240-
from threading import currentThread, RLock
240+
from threading import current_thread, RLock

Lib/logging/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def __init__(self, name, level, pathname, lineno,
258258
self.relativeCreated = (self.created - _startTime) * 1000
259259
if logThreads and thread:
260260
self.thread = thread.get_ident()
261-
self.threadName = threading.currentThread().getName()
261+
self.threadName = threading.current_thread().get_name()
262262
else:
263263
self.thread = None
264264
self.threadName = None

Lib/multiprocessing/dummy/__init__.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,17 @@ def start(self):
4848
threading.Thread.start(self)
4949

5050
def get_exitcode(self):
51-
if self._start_called and not self.isAlive():
51+
if self._start_called and not self.is_alive():
5252
return 0
5353
else:
5454
return None
5555

56-
# XXX
57-
if sys.version_info < (3, 0):
58-
is_alive = threading.Thread.isAlive.__func__
59-
get_name = threading.Thread.getName.__func__
60-
set_name = threading.Thread.setName.__func__
61-
is_daemon = threading.Thread.isDaemon.__func__
62-
set_daemon = threading.Thread.setDaemon.__func__
63-
else:
64-
is_alive = threading.Thread.isAlive
65-
get_name = threading.Thread.getName
66-
set_name = threading.Thread.setName
67-
is_daemon = threading.Thread.isDaemon
68-
set_daemon = threading.Thread.setDaemon
56+
57+
is_alive = threading.Thread.is_alive
58+
get_name = threading.Thread.get_name
59+
set_name = threading.Thread.set_name
60+
is_daemon = threading.Thread.is_daemon
61+
set_daemon = threading.Thread.set_daemon
6962

7063
#
7164
#
@@ -74,22 +67,22 @@ def get_exitcode(self):
7467
class Condition(threading._Condition):
7568
# XXX
7669
if sys.version_info < (3, 0):
77-
notify_all = threading._Condition.notifyAll.__func__
70+
notify_all = threading._Condition.notify_all.__func__
7871
else:
79-
notify_all = threading._Condition.notifyAll
72+
notify_all = threading._Condition.notify_all
8073

8174
#
8275
#
8376
#
8477

8578
Process = DummyProcess
86-
current_process = threading.currentThread
79+
current_process = threading.current_thread
8780
current_process()._children = weakref.WeakKeyDictionary()
8881

8982
def active_children():
9083
children = current_process()._children
9184
for p in list(children):
92-
if not p.isAlive():
85+
if not p.is_alive():
9386
children.pop(p, None)
9487
return list(children)
9588

Lib/multiprocessing/managers.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def serve_forever(self):
169169
except (OSError, IOError):
170170
continue
171171
t = threading.Thread(target=self.handle_request, args=(c,))
172-
t.setDaemon(True)
172+
t.set_daemon(True)
173173
t.start()
174174
except (KeyboardInterrupt, SystemExit):
175175
pass
@@ -216,7 +216,7 @@ def serve_client(self, conn):
216216
Handle requests from the proxies in a particular process/thread
217217
'''
218218
util.debug('starting server thread to service %r',
219-
threading.currentThread().getName())
219+
threading.current_thread().get_name())
220220

221221
recv = conn.recv
222222
send = conn.send
@@ -266,7 +266,7 @@ def serve_client(self, conn):
266266

267267
except EOFError:
268268
util.debug('got EOF -- exiting thread serving %r',
269-
threading.currentThread().getName())
269+
threading.current_thread().get_name())
270270
sys.exit(0)
271271

272272
except Exception:
@@ -279,7 +279,7 @@ def serve_client(self, conn):
279279
send(('#UNSERIALIZABLE', repr(msg)))
280280
except Exception as e:
281281
util.info('exception in thread serving %r',
282-
threading.currentThread().getName())
282+
threading.current_thread().get_name())
283283
util.info(' ... message was %r', msg)
284284
util.info(' ... exception was %r', e)
285285
conn.close()
@@ -401,7 +401,7 @@ def accept_connection(self, c, name):
401401
'''
402402
Spawn a new thread to serve this connection
403403
'''
404-
threading.currentThread().setName(name)
404+
threading.current_thread().set_name(name)
405405
c.send(('#RETURN', None))
406406
self.serve_client(c)
407407

@@ -715,8 +715,8 @@ def __init__(self, token, serializer, manager=None,
715715
def _connect(self):
716716
util.debug('making connection to manager')
717717
name = current_process().get_name()
718-
if threading.currentThread().getName() != 'MainThread':
719-
name += '|' + threading.currentThread().getName()
718+
if threading.current_thread().get_name() != 'MainThread':
719+
name += '|' + threading.current_thread().get_name()
720720
conn = self._Client(self._token.address, authkey=self._authkey)
721721
dispatch(conn, None, 'accept_connection', (name,))
722722
self._tls.connection = conn
@@ -729,7 +729,7 @@ def _callmethod(self, methodname, args=(), kwds={}):
729729
conn = self._tls.connection
730730
except AttributeError:
731731
util.debug('thread %r does not own a connection',
732-
threading.currentThread().getName())
732+
threading.current_thread().get_name())
733733
self._connect()
734734
conn = self._tls.connection
735735

@@ -790,7 +790,7 @@ def _decref(token, authkey, state, tls, idset, _Client):
790790
# the process owns no more references to objects for this manager
791791
if not idset and hasattr(tls, 'connection'):
792792
util.debug('thread %r has no more proxies so closing conn',
793-
threading.currentThread().getName())
793+
threading.current_thread().get_name())
794794
tls.connection.close()
795795
del tls.connection
796796

@@ -969,13 +969,13 @@ def __exit__(self, exc_type, exc_val, exc_tb):
969969

970970
class ConditionProxy(AcquirerProxy):
971971
# XXX will Condition.notfyAll() name be available in Py3.0?
972-
_exposed_ = ('acquire', 'release', 'wait', 'notify', 'notifyAll')
972+
_exposed_ = ('acquire', 'release', 'wait', 'notify', 'notify_all')
973973
def wait(self, timeout=None):
974974
return self._callmethod('wait', (timeout,))
975975
def notify(self):
976976
return self._callmethod('notify')
977977
def notify_all(self):
978-
return self._callmethod('notifyAll')
978+
return self._callmethod('notify_all')
979979

980980
class EventProxy(BaseProxy):
981981
# XXX will Event.isSet name be available in Py3.0?

Lib/multiprocessing/pool.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ def __init__(self, processes=None, initializer=None, initargs=()):
107107
target=Pool._handle_tasks,
108108
args=(self._taskqueue, self._quick_put, self._outqueue, self._pool)
109109
)
110-
self._task_handler.setDaemon(True)
110+
self._task_handler.set_daemon(True)
111111
self._task_handler._state = RUN
112112
self._task_handler.start()
113113

114114
self._result_handler = threading.Thread(
115115
target=Pool._handle_results,
116116
args=(self._outqueue, self._quick_get, self._cache)
117117
)
118-
self._result_handler.setDaemon(True)
118+
self._result_handler.set_daemon(True)
119119
self._result_handler._state = RUN
120120
self._result_handler.start()
121121

@@ -213,7 +213,7 @@ def map_async(self, func, iterable, chunksize=None, callback=None):
213213

214214
@staticmethod
215215
def _handle_tasks(taskqueue, put, outqueue, pool):
216-
thread = threading.currentThread()
216+
thread = threading.current_thread()
217217

218218
for taskseq, set_length in iter(taskqueue.get, None):
219219
i = -1
@@ -252,7 +252,7 @@ def _handle_tasks(taskqueue, put, outqueue, pool):
252252

253253
@staticmethod
254254
def _handle_results(outqueue, get, cache):
255-
thread = threading.currentThread()
255+
thread = threading.current_thread()
256256

257257
while 1:
258258
try:
@@ -346,7 +346,7 @@ def _help_stuff_finish(inqueue, task_handler, size):
346346
# task_handler may be blocked trying to put items on inqueue
347347
debug('removing tasks from inqueue until task handler finished')
348348
inqueue._rlock.acquire()
349-
while task_handler.isAlive() and inqueue._reader.poll():
349+
while task_handler.is_alive() and inqueue._reader.poll():
350350
inqueue._reader.recv()
351351
time.sleep(0)
352352

@@ -362,7 +362,7 @@ def _terminate_pool(cls, taskqueue, inqueue, outqueue, pool,
362362
debug('helping task handler/workers to finish')
363363
cls._help_stuff_finish(inqueue, task_handler, len(pool))
364364

365-
assert result_handler.isAlive() or len(cache) == 0
365+
assert result_handler.is_alive() or len(cache) == 0
366366

367367
result_handler._state = TERMINATE
368368
outqueue.put(None) # sentinel
@@ -591,6 +591,6 @@ def _help_stuff_finish(inqueue, task_handler, size):
591591
try:
592592
inqueue.queue.clear()
593593
inqueue.queue.extend([None] * size)
594-
inqueue.not_empty.notifyAll()
594+
inqueue.not_empty.notify_all()
595595
finally:
596596
inqueue.not_empty.release()

Lib/multiprocessing/queues.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _start_thread(self):
155155
self._wlock, self._writer.close),
156156
name='QueueFeederThread'
157157
)
158-
self._thread.setDaemon(True)
158+
self._thread.set_daemon(True)
159159

160160
debug('doing self._thread.start()')
161161
self._thread.start()

Lib/multiprocessing/reduction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _get_listener():
8484
debug('starting listener and thread for sending handles')
8585
_listener = Listener(authkey=current_process().get_authkey())
8686
t = threading.Thread(target=_serve)
87-
t.setDaemon(True)
87+
t.set_daemon(True)
8888
t.start()
8989
finally:
9090
_lock.release()

Lib/multiprocessing/synchronize.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def __repr__(self):
109109
try:
110110
if self._semlock._is_mine():
111111
name = current_process().get_name()
112-
if threading.currentThread().getName() != 'MainThread':
113-
name += '|' + threading.currentThread().getName()
112+
if threading.current_thread().get_name() != 'MainThread':
113+
name += '|' + threading.current_thread().get_name()
114114
elif self._semlock._get_value() == 1:
115115
name = 'None'
116116
elif self._semlock._count() > 0:
@@ -134,8 +134,8 @@ def __repr__(self):
134134
try:
135135
if self._semlock._is_mine():
136136
name = current_process().get_name()
137-
if threading.currentThread().getName() != 'MainThread':
138-
name += '|' + threading.currentThread().getName()
137+
if threading.current_thread().get_name() != 'MainThread':
138+
name += '|' + threading.current_thread().get_name()
139139
count = self._semlock._count()
140140
elif self._semlock._get_value() == 1:
141141
name, count = 'None', 0

0 commit comments

Comments
 (0)