Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
0fbcf694
Kaydet (Commit)
0fbcf694
authored
Haz 11, 2008
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
give the threading API PEP 8 names
üst
32c2e41c
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
127 additions
and
126 deletions
+127
-126
threading.rst
Doc/library/threading.rst
+19
-19
Queue.py
Lib/Queue.py
+1
-1
_threading_local.py
Lib/_threading_local.py
+4
-4
__init__.py
Lib/logging/__init__.py
+1
-1
__init__.py
Lib/multiprocessing/dummy/__init__.py
+15
-15
managers.py
Lib/multiprocessing/managers.py
+11
-11
pool.py
Lib/multiprocessing/pool.py
+7
-7
queues.py
Lib/multiprocessing/queues.py
+1
-1
reduction.py
Lib/multiprocessing/reduction.py
+1
-1
synchronize.py
Lib/multiprocessing/synchronize.py
+4
-4
test_dummy_threading.py
Lib/test/test_dummy_threading.py
+3
-3
test_multiprocessing.py
Lib/test/test_multiprocessing.py
+3
-3
test_queue.py
Lib/test/test_queue.py
+4
-4
test_smtplib.py
Lib/test/test_smtplib.py
+2
-2
test_socket.py
Lib/test/test_socket.py
+1
-1
test_socketserver.py
Lib/test/test_socketserver.py
+1
-1
test_threading.py
Lib/test/test_threading.py
+12
-12
threaded_import_hangers.py
Lib/test/threaded_import_hangers.py
+1
-1
threading.py
Lib/threading.py
+35
-35
NEWS
Misc/NEWS
+1
-0
No files found.
Doc/library/threading.rst
Dosyayı görüntüle @
0fbcf694
...
...
@@ -16,7 +16,7 @@ The :mod:`dummy_threading` module is provided for situations where
This module defines the following functions and objects:
.. function:: active
C
ount()
.. function:: active
_c
ount()
Return the number of :class:`Thread` objects currently alive. The returned
count is equal to the length of the list returned by :func:`enumerate`.
...
...
@@ -30,7 +30,7 @@ This module defines the following functions and objects:
thread.
.. function:: current
T
hread()
.. function:: current
_t
hread()
Return the current :class:`Thread` object, corresponding to the caller's thread
of control. If the caller's thread of control was not created through the
...
...
@@ -40,10 +40,10 @@ This module defines the following functions and objects:
.. function:: enumerate()
Return a list of all :class:`Thread` objects currently alive. The list
includes
daemonic threads, dummy thread objects created by :func:`currentThread`, and the
main thread. It excludes terminated threads and threads that have not yet been
started.
Return a list of all :class:`Thread` objects currently alive. The list
includes daemonic threads, dummy thread objects created by
:func:`current_thread`, and the main thread. It excludes terminated threads
and threads that have not yet been
started.
.. function:: Event()
...
...
@@ -395,7 +395,7 @@ needs to wake up one consumer thread.
lock, its caller should.
.. method:: Condition.notify
A
ll()
.. method:: Condition.notify
_a
ll()
Wake up all threads waiting on this condition. This method acts like
:meth:`notify`, but wakes up all waiting threads instead of one. If the calling
...
...
@@ -552,12 +552,12 @@ Other threads can call a thread's :meth:`join` method. This blocks the calling
thread until the thread whose :meth:`join` method is called is terminated.
A thread has a name. The name can be passed to the constructor, set with the
:meth:`set
Name` method, and retrieved with the :meth:`getN
ame` method.
:meth:`set
_name` method, and retrieved with the :meth:`get_n
ame` method.
A thread can be flagged as a "daemon thread". The significance of this flag is
that the entire Python program exits when only daemon threads are left. The
initial value is inherited from the creating thread. The flag can be set with
the :meth:`set
Daemon` method and retrieved with the :meth:`isD
aemon` method.
the :meth:`set
_daemon` method and retrieved with the :meth:`is_d
aemon` method.
There is a "main thread" object; this corresponds to the initial thread of
control in the Python program. It is not a daemon thread.
...
...
@@ -637,12 +637,12 @@ impossible to detect the termination of alien threads.
raises the same exception.
.. method:: Thread.get
N
ame()
.. method:: Thread.get
_n
ame()
Return the thread's name.
.. method:: Thread.set
N
ame(name)
.. method:: Thread.set
_s
ame(name)
Set the thread's name.
...
...
@@ -651,18 +651,18 @@ impossible to detect the termination of alien threads.
constructor.
.. method:: Thread.get
I
dent()
.. method:: Thread.get
_d
dent()
Return the 'thread identifier' of this thread or None if the thread has not
been started. This is a nonzero integer. See the :
mod:`thread` module's
:func:`get_ident()` function. Thread identifiers may be recycled when a
thread
exits and another thread is created. The identifier is returned
e
ven after the thread has e
xited.
been started. This is a nonzero integer. See the :
func:`thread.get_ident()`
function. Thread identifiers may be recycled when a thread exits and another
thread
is created. The identifier is returned even after the thread has
exited.
.. versionadded:: 2.6
.. method:: Thread.is
A
live()
.. method:: Thread.is
_a
live()
Return whether the thread is alive.
...
...
@@ -671,12 +671,12 @@ impossible to detect the termination of alien threads.
returns a list of all alive threads.
.. method:: Thread.is
D
aemon()
.. method:: Thread.is
_d
aemon()
Return the thread's daemon flag.
.. method:: Thread.set
D
aemon(daemonic)
.. method:: Thread.set
_d
aemon(daemonic)
Set the thread's daemon flag to the Boolean value *daemonic*. This must be
called before :meth:`start` is called, otherwise :exc:`RuntimeError` is raised.
...
...
Lib/Queue.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -62,7 +62,7 @@ class Queue:
if
unfinished
<=
0
:
if
unfinished
<
0
:
raise
ValueError
(
'task_done() called too many times'
)
self
.
all_tasks_done
.
notify
A
ll
()
self
.
all_tasks_done
.
notify
_a
ll
()
self
.
unfinished_tasks
=
unfinished
finally
:
self
.
all_tasks_done
.
release
()
...
...
Lib/_threading_local.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -162,16 +162,16 @@ class _localbase(object):
# __init__ being called, to make sure we don't call it
# again ourselves.
dict
=
object
.
__getattribute__
(
self
,
'__dict__'
)
current
T
hread
()
.
__dict__
[
key
]
=
dict
current
_t
hread
()
.
__dict__
[
key
]
=
dict
return
self
def
_patch
(
self
):
key
=
object
.
__getattribute__
(
self
,
'_local__key'
)
d
=
current
T
hread
()
.
__dict__
.
get
(
key
)
d
=
current
_t
hread
()
.
__dict__
.
get
(
key
)
if
d
is
None
:
d
=
{}
current
T
hread
()
.
__dict__
[
key
]
=
d
current
_t
hread
()
.
__dict__
[
key
]
=
d
object
.
__setattr__
(
self
,
'__dict__'
,
d
)
# we have a new instance dict, so call out __init__ if we have
...
...
@@ -238,4 +238,4 @@ class local(_localbase):
except
KeyError
:
pass
# didn't have anything in this thread
from
threading
import
current
T
hread
,
RLock
from
threading
import
current
_t
hread
,
RLock
Lib/logging/__init__.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -262,7 +262,7 @@ class LogRecord:
self
.
relativeCreated
=
(
self
.
created
-
_startTime
)
*
1000
if
logThreads
and
thread
:
self
.
thread
=
thread
.
get_ident
()
self
.
threadName
=
threading
.
current
Thread
()
.
getN
ame
()
self
.
threadName
=
threading
.
current
_thread
()
.
get_n
ame
()
else
:
self
.
thread
=
None
self
.
threadName
=
None
...
...
Lib/multiprocessing/dummy/__init__.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -48,24 +48,24 @@ class DummyProcess(threading.Thread):
threading
.
Thread
.
start
(
self
)
def
get_exitcode
(
self
):
if
self
.
_start_called
and
not
self
.
is
A
live
():
if
self
.
_start_called
and
not
self
.
is
_a
live
():
return
0
else
:
return
None
# XXX
if
sys
.
version_info
<
(
3
,
0
):
is_alive
=
threading
.
Thread
.
is
A
live
.
im_func
get_name
=
threading
.
Thread
.
get
N
ame
.
im_func
set_name
=
threading
.
Thread
.
set
N
ame
.
im_func
is_daemon
=
threading
.
Thread
.
is
D
aemon
.
im_func
set_daemon
=
threading
.
Thread
.
set
D
aemon
.
im_func
is_alive
=
threading
.
Thread
.
is
_a
live
.
im_func
get_name
=
threading
.
Thread
.
get
_n
ame
.
im_func
set_name
=
threading
.
Thread
.
set
_n
ame
.
im_func
is_daemon
=
threading
.
Thread
.
is
_d
aemon
.
im_func
set_daemon
=
threading
.
Thread
.
set
_d
aemon
.
im_func
else
:
is_alive
=
threading
.
Thread
.
is
A
live
get_name
=
threading
.
Thread
.
get
N
ame
set_name
=
threading
.
Thread
.
set
N
ame
is_daemon
=
threading
.
Thread
.
is
D
aemon
set_daemon
=
threading
.
Thread
.
set
D
aemon
is_alive
=
threading
.
Thread
.
is
_a
live
get_name
=
threading
.
Thread
.
get
_n
ame
set_name
=
threading
.
Thread
.
set
_n
ame
is_daemon
=
threading
.
Thread
.
is
_d
aemon
set_daemon
=
threading
.
Thread
.
set
_d
aemon
#
#
...
...
@@ -74,22 +74,22 @@ class DummyProcess(threading.Thread):
class
Condition
(
threading
.
_Condition
):
# XXX
if
sys
.
version_info
<
(
3
,
0
):
notify_all
=
threading
.
_Condition
.
notify
A
ll
.
im_func
notify_all
=
threading
.
_Condition
.
notify
_a
ll
.
im_func
else
:
notify_all
=
threading
.
_Condition
.
notify
A
ll
notify_all
=
threading
.
_Condition
.
notify
_a
ll
#
#
#
Process
=
DummyProcess
current_process
=
threading
.
current
T
hread
current_process
=
threading
.
current
_t
hread
current_process
()
.
_children
=
weakref
.
WeakKeyDictionary
()
def
active_children
():
children
=
current_process
()
.
_children
for
p
in
list
(
children
):
if
not
p
.
is
A
live
():
if
not
p
.
is
_a
live
():
children
.
pop
(
p
,
None
)
return
list
(
children
)
...
...
Lib/multiprocessing/managers.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -169,7 +169,7 @@ class Server(object):
except
(
OSError
,
IOError
):
continue
t
=
threading
.
Thread
(
target
=
self
.
handle_request
,
args
=
(
c
,))
t
.
set
D
aemon
(
True
)
t
.
set
_d
aemon
(
True
)
t
.
start
()
except
(
KeyboardInterrupt
,
SystemExit
):
pass
...
...
@@ -216,7 +216,7 @@ class Server(object):
Handle requests from the proxies in a particular process/thread
'''
util
.
debug
(
'starting server thread to service
%
r'
,
threading
.
current
Thread
()
.
getN
ame
())
threading
.
current
_thread
()
.
get_n
ame
())
recv
=
conn
.
recv
send
=
conn
.
send
...
...
@@ -266,7 +266,7 @@ class Server(object):
except
EOFError
:
util
.
debug
(
'got EOF -- exiting thread serving
%
r'
,
threading
.
current
Thread
()
.
getN
ame
())
threading
.
current
_thread
()
.
get_n
ame
())
sys
.
exit
(
0
)
except
Exception
:
...
...
@@ -279,7 +279,7 @@ class Server(object):
send
((
'#UNSERIALIZABLE'
,
repr
(
msg
)))
except
Exception
,
e
:
util
.
info
(
'exception in thread serving
%
r'
,
threading
.
current
Thread
()
.
getN
ame
())
threading
.
current
_thread
()
.
get_n
ame
())
util
.
info
(
' ... message was
%
r'
,
msg
)
util
.
info
(
' ... exception was
%
r'
,
e
)
conn
.
close
()
...
...
@@ -401,7 +401,7 @@ class Server(object):
'''
Spawn a new thread to serve this connection
'''
threading
.
current
Thread
()
.
setN
ame
(
name
)
threading
.
current
_thread
()
.
set_n
ame
(
name
)
c
.
send
((
'#RETURN'
,
None
))
self
.
serve_client
(
c
)
...
...
@@ -715,8 +715,8 @@ class BaseProxy(object):
def
_connect
(
self
):
util
.
debug
(
'making connection to manager'
)
name
=
current_process
()
.
get_name
()
if
threading
.
current
Thread
()
.
getN
ame
()
!=
'MainThread'
:
name
+=
'|'
+
threading
.
current
Thread
()
.
getN
ame
()
if
threading
.
current
_thread
()
.
get_n
ame
()
!=
'MainThread'
:
name
+=
'|'
+
threading
.
current
_thread
()
.
get_n
ame
()
conn
=
self
.
_Client
(
self
.
_token
.
address
,
authkey
=
self
.
_authkey
)
dispatch
(
conn
,
None
,
'accept_connection'
,
(
name
,))
self
.
_tls
.
connection
=
conn
...
...
@@ -729,7 +729,7 @@ class BaseProxy(object):
conn
=
self
.
_tls
.
connection
except
AttributeError
:
util
.
debug
(
'thread
%
r does not own a connection'
,
threading
.
current
Thread
()
.
getN
ame
())
threading
.
current
_thread
()
.
get_n
ame
())
self
.
_connect
()
conn
=
self
.
_tls
.
connection
...
...
@@ -790,7 +790,7 @@ class BaseProxy(object):
# the process owns no more references to objects for this manager
if
not
idset
and
hasattr
(
tls
,
'connection'
):
util
.
debug
(
'thread
%
r has no more proxies so closing conn'
,
threading
.
current
Thread
()
.
getN
ame
())
threading
.
current
_thread
()
.
get_n
ame
())
tls
.
connection
.
close
()
del
tls
.
connection
...
...
@@ -969,13 +969,13 @@ class AcquirerProxy(BaseProxy):
class
ConditionProxy
(
AcquirerProxy
):
# XXX will Condition.notfyAll() name be available in Py3.0?
_exposed_
=
(
'acquire'
,
'release'
,
'wait'
,
'notify'
,
'notify
A
ll'
)
_exposed_
=
(
'acquire'
,
'release'
,
'wait'
,
'notify'
,
'notify
_a
ll'
)
def
wait
(
self
,
timeout
=
None
):
return
self
.
_callmethod
(
'wait'
,
(
timeout
,))
def
notify
(
self
):
return
self
.
_callmethod
(
'notify'
)
def
notify_all
(
self
):
return
self
.
_callmethod
(
'notify
A
ll'
)
return
self
.
_callmethod
(
'notify
_a
ll'
)
class
EventProxy
(
BaseProxy
):
# XXX will Event.isSet name be available in Py3.0?
...
...
Lib/multiprocessing/pool.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -107,7 +107,7 @@ class Pool(object):
target
=
Pool
.
_handle_tasks
,
args
=
(
self
.
_taskqueue
,
self
.
_quick_put
,
self
.
_outqueue
,
self
.
_pool
)
)
self
.
_task_handler
.
set
D
aemon
(
True
)
self
.
_task_handler
.
set
_d
aemon
(
True
)
self
.
_task_handler
.
_state
=
RUN
self
.
_task_handler
.
start
()
...
...
@@ -115,7 +115,7 @@ class Pool(object):
target
=
Pool
.
_handle_results
,
args
=
(
self
.
_outqueue
,
self
.
_quick_get
,
self
.
_cache
)
)
self
.
_result_handler
.
set
D
aemon
(
True
)
self
.
_result_handler
.
set
_d
aemon
(
True
)
self
.
_result_handler
.
_state
=
RUN
self
.
_result_handler
.
start
()
...
...
@@ -213,7 +213,7 @@ class Pool(object):
@staticmethod
def
_handle_tasks
(
taskqueue
,
put
,
outqueue
,
pool
):
thread
=
threading
.
current
T
hread
()
thread
=
threading
.
current
_t
hread
()
for
taskseq
,
set_length
in
iter
(
taskqueue
.
get
,
None
):
i
=
-
1
...
...
@@ -252,7 +252,7 @@ class Pool(object):
@staticmethod
def
_handle_results
(
outqueue
,
get
,
cache
):
thread
=
threading
.
current
T
hread
()
thread
=
threading
.
current
_t
hread
()
while
1
:
try
:
...
...
@@ -346,7 +346,7 @@ class Pool(object):
# task_handler may be blocked trying to put items on inqueue
debug
(
'removing tasks from inqueue until task handler finished'
)
inqueue
.
_rlock
.
acquire
()
while
task_handler
.
is
A
live
()
and
inqueue
.
_reader
.
poll
():
while
task_handler
.
is
_a
live
()
and
inqueue
.
_reader
.
poll
():
inqueue
.
_reader
.
recv
()
time
.
sleep
(
0
)
...
...
@@ -362,7 +362,7 @@ class Pool(object):
debug
(
'helping task handler/workers to finish'
)
cls
.
_help_stuff_finish
(
inqueue
,
task_handler
,
len
(
pool
))
assert
result_handler
.
is
A
live
()
or
len
(
cache
)
==
0
assert
result_handler
.
is
_a
live
()
or
len
(
cache
)
==
0
result_handler
.
_state
=
TERMINATE
outqueue
.
put
(
None
)
# sentinel
...
...
@@ -591,6 +591,6 @@ class ThreadPool(Pool):
try
:
inqueue
.
queue
.
clear
()
inqueue
.
queue
.
extend
([
None
]
*
size
)
inqueue
.
not_empty
.
notify
A
ll
()
inqueue
.
not_empty
.
notify
_a
ll
()
finally
:
inqueue
.
not_empty
.
release
()
Lib/multiprocessing/queues.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -155,7 +155,7 @@ class Queue(object):
self
.
_wlock
,
self
.
_writer
.
close
),
name
=
'QueueFeederThread'
)
self
.
_thread
.
set
D
aemon
(
True
)
self
.
_thread
.
set
_d
aemon
(
True
)
debug
(
'doing self._thread.start()'
)
self
.
_thread
.
start
()
...
...
Lib/multiprocessing/reduction.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -84,7 +84,7 @@ def _get_listener():
debug
(
'starting listener and thread for sending handles'
)
_listener
=
Listener
(
authkey
=
current_process
()
.
get_authkey
())
t
=
threading
.
Thread
(
target
=
_serve
)
t
.
set
D
aemon
(
True
)
t
.
set
_d
aemon
(
True
)
t
.
start
()
finally
:
_lock
.
release
()
...
...
Lib/multiprocessing/synchronize.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -109,8 +109,8 @@ class Lock(SemLock):
try
:
if
self
.
_semlock
.
_is_mine
():
name
=
current_process
()
.
get_name
()
if
threading
.
current
Thread
()
.
getN
ame
()
!=
'MainThread'
:
name
+=
'|'
+
threading
.
current
Thread
()
.
getN
ame
()
if
threading
.
current
_thread
()
.
get_n
ame
()
!=
'MainThread'
:
name
+=
'|'
+
threading
.
current
_thread
()
.
get_n
ame
()
elif
self
.
_semlock
.
_get_value
()
==
1
:
name
=
'None'
elif
self
.
_semlock
.
_count
()
>
0
:
...
...
@@ -134,8 +134,8 @@ class RLock(SemLock):
try
:
if
self
.
_semlock
.
_is_mine
():
name
=
current_process
()
.
get_name
()
if
threading
.
current
Thread
()
.
getN
ame
()
!=
'MainThread'
:
name
+=
'|'
+
threading
.
current
Thread
()
.
getN
ame
()
if
threading
.
current
_thread
()
.
get_n
ame
()
!=
'MainThread'
:
name
+=
'|'
+
threading
.
current
_thread
()
.
get_n
ame
()
count
=
self
.
_semlock
.
_count
()
elif
self
.
_semlock
.
_get_value
()
==
1
:
name
,
count
=
'None'
,
0
...
...
Lib/test/test_dummy_threading.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -16,7 +16,7 @@ class DummyThreadingTestCase(unittest.TestCase):
#delay = random.random() * 2
delay
=
0
if
test_support
.
verbose
:
print
'task'
,
self
.
get
N
ame
(),
'will run for'
,
delay
,
'sec'
print
'task'
,
self
.
get
_n
ame
(),
'will run for'
,
delay
,
'sec'
sema
.
acquire
()
mutex
.
acquire
()
running
+=
1
...
...
@@ -25,11 +25,11 @@ class DummyThreadingTestCase(unittest.TestCase):
mutex
.
release
()
time
.
sleep
(
delay
)
if
test_support
.
verbose
:
print
'task'
,
self
.
get
N
ame
(),
'done'
print
'task'
,
self
.
get
_n
ame
(),
'done'
mutex
.
acquire
()
running
-=
1
if
test_support
.
verbose
:
print
self
.
get
N
ame
(),
'is finished.'
,
running
,
'tasks are running'
print
self
.
get
_n
ame
(),
'is finished.'
,
running
,
'tasks are running'
mutex
.
release
()
sema
.
release
()
...
...
Lib/test/test_multiprocessing.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -632,7 +632,7 @@ class _TestCondition(BaseTestCase):
p
.
start
()
p
=
threading
.
Thread
(
target
=
self
.
f
,
args
=
(
cond
,
sleeping
,
woken
))
p
.
set
D
aemon
(
True
)
p
.
set
_d
aemon
(
True
)
p
.
start
()
# wait for both children to start sleeping
...
...
@@ -679,7 +679,7 @@ class _TestCondition(BaseTestCase):
t
=
threading
.
Thread
(
target
=
self
.
f
,
args
=
(
cond
,
sleeping
,
woken
,
TIMEOUT1
))
t
.
set
D
aemon
(
True
)
t
.
set
_d
aemon
(
True
)
t
.
start
()
# wait for them all to sleep
...
...
@@ -701,7 +701,7 @@ class _TestCondition(BaseTestCase):
p
.
start
()
t
=
threading
.
Thread
(
target
=
self
.
f
,
args
=
(
cond
,
sleeping
,
woken
))
t
.
set
D
aemon
(
True
)
t
.
set
_d
aemon
(
True
)
t
.
start
()
# wait for them to all sleep
...
...
Lib/test/test_queue.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -49,11 +49,11 @@ class BlockingTestMixin:
self
.
t
.
start
()
self
.
result
=
block_func
(
*
block_args
)
# If block_func returned before our thread made the call, we failed!
if
not
self
.
t
.
startedEvent
.
is
S
et
():
if
not
self
.
t
.
startedEvent
.
is
_s
et
():
self
.
fail
(
"blocking function '
%
r' appeared not to block"
%
block_func
)
self
.
t
.
join
(
10
)
# make sure the thread terminates
if
self
.
t
.
is
A
live
():
if
self
.
t
.
is
_a
live
():
self
.
fail
(
"trigger function '
%
r' appeared to not return"
%
trigger_func
)
return
self
.
result
...
...
@@ -73,10 +73,10 @@ class BlockingTestMixin:
expected_exception_class
)
finally
:
self
.
t
.
join
(
10
)
# make sure the thread terminates
if
self
.
t
.
is
A
live
():
if
self
.
t
.
is
_a
live
():
self
.
fail
(
"trigger function '
%
r' appeared to not return"
%
trigger_func
)
if
not
self
.
t
.
startedEvent
.
is
S
et
():
if
not
self
.
t
.
startedEvent
.
is
_s
et
():
self
.
fail
(
"trigger thread ended but event never set"
)
...
...
Lib/test/test_smtplib.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -109,7 +109,7 @@ def debugging_server(serv, serv_evt, client_evt):
# when the client conversation is finished, it will
# set client_evt, and it's then ok to kill the server
if
client_evt
.
is
S
et
():
if
client_evt
.
is
_s
et
():
serv
.
close
()
break
...
...
@@ -118,7 +118,7 @@ def debugging_server(serv, serv_evt, client_evt):
except
socket
.
timeout
:
pass
finally
:
if
not
client_evt
.
is
S
et
():
if
not
client_evt
.
is
_s
et
():
# allow some time for the client to read the result
time
.
sleep
(
0.5
)
serv
.
close
()
...
...
Lib/test/test_socket.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -107,7 +107,7 @@ class ThreadableTest:
self
.
clientRun
,
(
test_method
,))
self
.
__setUp
()
if
not
self
.
server_ready
.
is
S
et
():
if
not
self
.
server_ready
.
is
_s
et
():
self
.
server_ready
.
set
()
self
.
client_ready
.
wait
()
...
...
Lib/test/test_socketserver.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -139,7 +139,7 @@ class SocketServerTest(unittest.TestCase):
# Time between requests is short enough that we won't wake
# up spuriously too many times.
kwargs
=
{
'poll_interval'
:
0.01
})
t
.
set
D
aemon
(
True
)
# In case this function raises.
t
.
set
_d
aemon
(
True
)
# In case this function raises.
t
.
start
()
if
verbose
:
print
"server running"
for
i
in
range
(
3
):
...
...
Lib/test/test_threading.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -34,7 +34,7 @@ class TestThread(threading.Thread):
delay
=
random
.
random
()
/
10000.0
if
verbose
:
print
'task
%
s will run for
%.1
f usec'
%
(
self
.
get
N
ame
(),
delay
*
1e6
)
self
.
get
_n
ame
(),
delay
*
1e6
)
with
self
.
sema
:
with
self
.
mutex
:
...
...
@@ -45,14 +45,14 @@ class TestThread(threading.Thread):
time
.
sleep
(
delay
)
if
verbose
:
print
'task'
,
self
.
get
N
ame
(),
'done'
print
'task'
,
self
.
get
_n
ame
(),
'done'
with
self
.
mutex
:
self
.
nrunning
.
dec
()
self
.
testcase
.
assert_
(
self
.
nrunning
.
get
()
>=
0
)
if
verbose
:
print
'
%
s is finished.
%
d tasks are running'
%
(
self
.
get
N
ame
(),
self
.
nrunning
.
get
())
self
.
get
_n
ame
(),
self
.
nrunning
.
get
())
class
ThreadTests
(
unittest
.
TestCase
):
...
...
@@ -73,7 +73,7 @@ class ThreadTests(unittest.TestCase):
for
i
in
range
(
NUMTASKS
):
t
=
TestThread
(
"<thread
%
d>"
%
i
,
self
,
sema
,
mutex
,
numrunning
)
threads
.
append
(
t
)
self
.
failUnlessEqual
(
t
.
get
I
dent
(),
None
)
self
.
failUnlessEqual
(
t
.
get
_i
dent
(),
None
)
self
.
assert_
(
re
.
match
(
'<TestThread
\
(.*, initial
\
)>'
,
repr
(
t
)))
t
.
start
()
...
...
@@ -81,8 +81,8 @@ class ThreadTests(unittest.TestCase):
print
'waiting for all tasks to complete'
for
t
in
threads
:
t
.
join
(
NUMTASKS
)
self
.
assert_
(
not
t
.
is
A
live
())
self
.
failIfEqual
(
t
.
get
I
dent
(),
0
)
self
.
assert_
(
not
t
.
is
_a
live
())
self
.
failIfEqual
(
t
.
get
_i
dent
(),
0
)
self
.
assert_
(
re
.
match
(
'<TestThread
\
(.*,
\
w+ -?
\
d+
\
)>'
,
repr
(
t
)))
if
verbose
:
print
'all tasks done'
...
...
@@ -172,7 +172,7 @@ class ThreadTests(unittest.TestCase):
worker_saw_exception
.
set
()
t
=
Worker
()
t
.
set
D
aemon
(
True
)
# so if this fails, we don't hang Python at shutdown
t
.
set
_d
aemon
(
True
)
# so if this fails, we don't hang Python at shutdown
t
.
start
()
if
verbose
:
print
" started worker thread"
...
...
@@ -258,12 +258,12 @@ class ThreadTests(unittest.TestCase):
print 'program blocked; aborting'
os._exit(2)
t = threading.Thread(target=killer)
t.set
D
aemon(True)
t.set
_d
aemon(True)
t.start()
# This is the trace function
def func(frame, event, arg):
threading.current
T
hread()
threading.current
_t
hread()
return func
sys.settrace(func)
...
...
@@ -348,8 +348,8 @@ class ThreadingExceptionTests(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
threading
.
Semaphore
,
value
=
-
sys
.
maxint
)
def
test_joining_current_thread
(
self
):
current
Thread
=
threading
.
currentT
hread
()
self
.
assertRaises
(
RuntimeError
,
current
T
hread
.
join
);
current
_thread
=
threading
.
current_t
hread
()
self
.
assertRaises
(
RuntimeError
,
current
_t
hread
.
join
);
def
test_joining_inactive_thread
(
self
):
thread
=
threading
.
Thread
()
...
...
@@ -358,7 +358,7 @@ class ThreadingExceptionTests(unittest.TestCase):
def
test_daemonize_active_thread
(
self
):
thread
=
threading
.
Thread
()
thread
.
start
()
self
.
assertRaises
(
RuntimeError
,
thread
.
set
D
aemon
,
True
)
self
.
assertRaises
(
RuntimeError
,
thread
.
set
_d
aemon
,
True
)
def
test_main
():
...
...
Lib/test/threaded_import_hangers.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -38,5 +38,5 @@ for name, func, args in [
t
=
Worker
(
func
,
args
)
t
.
start
()
t
.
join
(
TIMEOUT
)
if
t
.
is
A
live
():
if
t
.
is
_a
live
():
errors
.
append
(
"
%
s appeared to hang"
%
name
)
Lib/threading.py
Dosyayı görüntüle @
0fbcf694
...
...
@@ -14,7 +14,7 @@ from traceback import format_exc as _format_exc
from
collections
import
deque
# Rename some stuff so "from threading import *" is safe
__all__
=
[
'active
Count'
,
'Condition'
,
'currentT
hread'
,
'enumerate'
,
'Event'
,
__all__
=
[
'active
_count'
,
'Condition'
,
'current_t
hread'
,
'enumerate'
,
'Event'
,
'Lock'
,
'RLock'
,
'Semaphore'
,
'BoundedSemaphore'
,
'Thread'
,
'Timer'
,
'setprofile'
,
'settrace'
,
'local'
,
'stack_size'
]
...
...
@@ -52,7 +52,7 @@ if __debug__:
if
self
.
__verbose
:
format
=
format
%
args
format
=
"
%
s:
%
s
\n
"
%
(
current
Thread
()
.
getN
ame
(),
format
)
current
_thread
()
.
get_n
ame
(),
format
)
_sys
.
stderr
.
write
(
format
)
else
:
...
...
@@ -95,11 +95,11 @@ class _RLock(_Verbose):
owner
=
self
.
__owner
return
"<
%
s(
%
s,
%
d)>"
%
(
self
.
__class__
.
__name__
,
owner
and
owner
.
get
N
ame
(),
owner
and
owner
.
get
_n
ame
(),
self
.
__count
)
def
acquire
(
self
,
blocking
=
1
):
me
=
current
T
hread
()
me
=
current
_t
hread
()
if
self
.
__owner
is
me
:
self
.
__count
=
self
.
__count
+
1
if
__debug__
:
...
...
@@ -119,7 +119,7 @@ class _RLock(_Verbose):
__enter__
=
acquire
def
release
(
self
):
if
self
.
__owner
is
not
current
T
hread
():
if
self
.
__owner
is
not
current
_t
hread
():
raise
RuntimeError
(
"cannot release un-aquired lock"
)
self
.
__count
=
count
=
self
.
__count
-
1
if
not
count
:
...
...
@@ -154,7 +154,7 @@ class _RLock(_Verbose):
return
(
count
,
owner
)
def
_is_owned
(
self
):
return
self
.
__owner
is
current
T
hread
()
return
self
.
__owner
is
current
_t
hread
()
def
Condition
(
*
args
,
**
kwargs
):
...
...
@@ -203,7 +203,7 @@ class _Condition(_Verbose):
self
.
__lock
.
acquire
()
# Ignore saved state
def
_is_owned
(
self
):
# Return True if lock is owned by current
T
hread.
# Return True if lock is owned by current
_t
hread.
# This method is called only if __lock doesn't have _is_owned().
if
self
.
__lock
.
acquire
(
0
):
self
.
__lock
.
release
()
...
...
@@ -271,7 +271,7 @@ class _Condition(_Verbose):
except
ValueError
:
pass
def
notify
A
ll
(
self
):
def
notify
_a
ll
(
self
):
self
.
notify
(
len
(
self
.
__waiters
))
...
...
@@ -350,14 +350,14 @@ class _Event(_Verbose):
self
.
__cond
=
Condition
(
Lock
())
self
.
__flag
=
False
def
is
S
et
(
self
):
def
is
_s
et
(
self
):
return
self
.
__flag
def
set
(
self
):
self
.
__cond
.
acquire
()
try
:
self
.
__flag
=
True
self
.
__cond
.
notify
A
ll
()
self
.
__cond
.
notify
_a
ll
()
finally
:
self
.
__cond
.
release
()
...
...
@@ -425,12 +425,12 @@ class Thread(_Verbose):
def
_set_daemon
(
self
):
# Overridden in _MainThread and _DummyThread
return
current
Thread
()
.
isD
aemon
()
return
current
_thread
()
.
is_d
aemon
()
def
__repr__
(
self
):
assert
self
.
__initialized
,
"Thread.__init__() was not called"
status
=
"initial"
if
self
.
__started
.
is
S
et
():
if
self
.
__started
.
is
_s
et
():
status
=
"started"
if
self
.
__stopped
:
status
=
"stopped"
...
...
@@ -443,7 +443,7 @@ class Thread(_Verbose):
def
start
(
self
):
if
not
self
.
__initialized
:
raise
RuntimeError
(
"thread.__init__() not called"
)
if
self
.
__started
.
is
S
et
():
if
self
.
__started
.
is
_s
et
():
raise
RuntimeError
(
"thread already started"
)
if
__debug__
:
self
.
_note
(
"
%
s.start(): starting thread"
,
self
)
...
...
@@ -514,7 +514,7 @@ class Thread(_Verbose):
# self.
if
_sys
:
_sys
.
stderr
.
write
(
"Exception in thread
%
s:
\n
%
s
\n
"
%
(
self
.
get
N
ame
(),
_format_exc
()))
(
self
.
get
_n
ame
(),
_format_exc
()))
else
:
# Do the best job possible w/o a huge amt. of code to
# approximate a traceback (code ideas from
...
...
@@ -522,7 +522,7 @@ class Thread(_Verbose):
exc_type
,
exc_value
,
exc_tb
=
self
.
__exc_info
()
try
:
print
>>
self
.
__stderr
,
(
"Exception in thread "
+
self
.
get
N
ame
()
+
"Exception in thread "
+
self
.
get
_n
ame
()
+
" (most likely raised during interpreter shutdown):"
)
print
>>
self
.
__stderr
,
(
"Traceback (most recent call last):"
)
...
...
@@ -560,7 +560,7 @@ class Thread(_Verbose):
def
__stop
(
self
):
self
.
__block
.
acquire
()
self
.
__stopped
=
True
self
.
__block
.
notify
A
ll
()
self
.
__block
.
notify
_a
ll
()
self
.
__block
.
release
()
def
__delete
(
self
):
...
...
@@ -593,7 +593,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
# current
T
hread()), and would block.
# current
_t
hread()), and would block.
except
KeyError
:
if
'dummy_threading'
not
in
_sys
.
modules
:
raise
...
...
@@ -601,9 +601,9 @@ class Thread(_Verbose):
def
join
(
self
,
timeout
=
None
):
if
not
self
.
__initialized
:
raise
RuntimeError
(
"Thread.__init__() not called"
)
if
not
self
.
__started
.
is
S
et
():
if
not
self
.
__started
.
is
_s
et
():
raise
RuntimeError
(
"cannot join thread before it is started"
)
if
self
is
current
T
hread
():
if
self
is
current
_t
hread
():
raise
RuntimeError
(
"cannot join current thread"
)
if
__debug__
:
...
...
@@ -631,30 +631,30 @@ class Thread(_Verbose):
finally
:
self
.
__block
.
release
()
def
get
N
ame
(
self
):
def
get
_n
ame
(
self
):
assert
self
.
__initialized
,
"Thread.__init__() not called"
return
self
.
__name
def
set
N
ame
(
self
,
name
):
def
set
_n
ame
(
self
,
name
):
assert
self
.
__initialized
,
"Thread.__init__() not called"
self
.
__name
=
str
(
name
)
def
get
I
dent
(
self
):
def
get
_i
dent
(
self
):
assert
self
.
__initialized
,
"Thread.__init__() not called"
return
self
.
__ident
def
is
A
live
(
self
):
def
is
_a
live
(
self
):
assert
self
.
__initialized
,
"Thread.__init__() not called"
return
self
.
__started
.
is
S
et
()
and
not
self
.
__stopped
return
self
.
__started
.
is
_s
et
()
and
not
self
.
__stopped
def
is
D
aemon
(
self
):
def
is
_d
aemon
(
self
):
assert
self
.
__initialized
,
"Thread.__init__() not called"
return
self
.
__daemonic
def
set
D
aemon
(
self
,
daemonic
):
def
set
_d
aemon
(
self
,
daemonic
):
if
not
self
.
__initialized
:
raise
RuntimeError
(
"Thread.__init__() not called"
)
if
self
.
__started
.
is
S
et
():
if
self
.
__started
.
is
_s
et
():
raise
RuntimeError
(
"cannot set daemon status of active thread"
);
self
.
__daemonic
=
daemonic
...
...
@@ -685,7 +685,7 @@ class _Timer(Thread):
def
run
(
self
):
self
.
finished
.
wait
(
self
.
interval
)
if
not
self
.
finished
.
is
S
et
():
if
not
self
.
finished
.
is
_s
et
():
self
.
function
(
*
self
.
args
,
**
self
.
kwargs
)
self
.
finished
.
set
()
...
...
@@ -719,16 +719,16 @@ class _MainThread(Thread):
def
_pickSomeNonDaemonThread
():
for
t
in
enumerate
():
if
not
t
.
is
Daemon
()
and
t
.
isA
live
():
if
not
t
.
is
_daemon
()
and
t
.
is_a
live
():
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 current
T
hread(), they
# If they invoke anything in threading.py that calls current
_t
hread(), they
# leave an entry in the _active dict forever after.
# Their purpose is to return *something* from current
T
hread().
# Their purpose is to return *something* from current
_t
hread().
# They are marked as daemon threads so we won't wait for them
# when we exit (conform previous semantics).
...
...
@@ -756,14 +756,14 @@ class _DummyThread(Thread):
# Global API functions
def
current
T
hread
():
def
current
_t
hread
():
try
:
return
_active
[
_get_ident
()]
except
KeyError
:
##print "current
T
hread(): no current thread for", _get_ident()
##print "current
_t
hread(): no current thread for", _get_ident()
return
_DummyThread
()
def
active
C
ount
():
def
active
_c
ount
():
_active_limbo_lock
.
acquire
()
count
=
len
(
_active
)
+
len
(
_limbo
)
_active_limbo_lock
.
release
()
...
...
@@ -840,7 +840,7 @@ def _test():
counter
=
0
while
counter
<
self
.
quota
:
counter
=
counter
+
1
self
.
queue
.
put
(
"
%
s.
%
d"
%
(
self
.
get
N
ame
(),
counter
))
self
.
queue
.
put
(
"
%
s.
%
d"
%
(
self
.
get
_n
ame
(),
counter
))
_sleep
(
random
()
*
0.00001
)
...
...
Misc/NEWS
Dosyayı görüntüle @
0fbcf694
...
...
@@ -291,6 +291,7 @@ Library
- The bundled OSX-specific copy of libbffi is now in sync with the version
shipped with PyObjC 2.0 and includes support for x86_64 and ppc64 platforms.
Build
-----
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment