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
cbae8697
Kaydet (Commit)
cbae8697
authored
Agu 18, 2008
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
backport threading property changes
üst
d8a8972c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
24 deletions
+18
-24
test_threading.py
Lib/test/test_threading.py
+6
-6
threading.py
Lib/threading.py
+12
-18
No files found.
Lib/test/test_threading.py
Dosyayı görüntüle @
cbae8697
...
...
@@ -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_name
()
,
delay
*
1e6
)
self
.
name
,
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_name
()
,
'done'
print
'task'
,
self
.
name
,
'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_name
()
,
self
.
nrunning
.
get
())
self
.
name
,
self
.
nrunning
.
get
())
class
ThreadTests
(
unittest
.
TestCase
):
...
...
@@ -172,7 +172,7 @@ class ThreadTests(unittest.TestCase):
worker_saw_exception
.
set
()
t
=
Worker
()
t
.
set_daemon
(
True
)
# so if this fails, we don't hang Python at shutdown
t
.
daemon
=
True
# so if this fails, we don't hang Python at shutdown
t
.
start
()
if
verbose
:
print
" started worker thread"
...
...
@@ -258,7 +258,7 @@ class ThreadTests(unittest.TestCase):
print 'program blocked; aborting'
os._exit(2)
t = threading.Thread(target=killer)
t.
set_daemon(True)
t.
daemon = True
t.start()
# This is the trace function
...
...
@@ -435,7 +435,7 @@ class ThreadingExceptionTests(unittest.TestCase):
def
test_daemonize_active_thread
(
self
):
thread
=
threading
.
Thread
()
thread
.
start
()
self
.
assertRaises
(
RuntimeError
,
thread
.
set_daemon
,
True
)
self
.
assertRaises
(
RuntimeError
,
setattr
,
thread
,
"daemon"
,
True
)
def
test_main
():
...
...
Lib/threading.py
Dosyayı görüntüle @
cbae8697
...
...
@@ -445,7 +445,7 @@ class Thread(_Verbose):
def
_set_daemon
(
self
):
# Overridden in _MainThread and _DummyThread
return
current_thread
()
.
is_daemon
()
return
current_thread
()
.
daemon
def
__repr__
(
self
):
assert
self
.
__initialized
,
"Thread.__init__() was not called"
...
...
@@ -651,18 +651,16 @@ class Thread(_Verbose):
finally
:
self
.
__block
.
release
()
def
get_name
(
self
):
@property
def
name
(
self
):
assert
self
.
__initialized
,
"Thread.__init__() not called"
return
self
.
__name
getName
=
_old_api
(
get_name
,
"getName"
)
def
set_name
(
self
,
name
):
@name.setter
def
name
(
self
,
name
):
assert
self
.
__initialized
,
"Thread.__init__() not called"
self
.
__name
=
str
(
name
)
setName
=
_old_api
(
set_name
,
"setName"
)
@property
def
ident
(
self
):
assert
self
.
__initialized
,
"Thread.__init__() not called"
...
...
@@ -672,23 +670,19 @@ class Thread(_Verbose):
assert
self
.
__initialized
,
"Thread.__init__() not called"
return
self
.
__started
.
is_set
()
and
not
self
.
__stopped
isAlive
=
_old_api
(
is_alive
,
"isAlive"
)
def
is_daemon
(
self
):
@property
def
daemon
(
self
):
assert
self
.
__initialized
,
"Thread.__init__() not called"
return
self
.
__daemonic
isDaemon
=
_old_api
(
is_daemon
,
"isDaemon"
)
def
set_daemon
(
self
,
daemonic
):
@daemon.setter
def
daemon
(
self
,
daemonic
):
if
not
self
.
__initialized
:
raise
RuntimeError
(
"Thread.__init__() not called"
)
if
self
.
__started
.
is_set
():
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
):
...
...
@@ -750,7 +744,7 @@ class _MainThread(Thread):
def
_pickSomeNonDaemonThread
():
for
t
in
enumerate
():
if
not
t
.
is_daemon
()
and
t
.
is_alive
():
if
not
t
.
daemon
and
t
.
is_alive
():
return
t
return
None
...
...
@@ -906,7 +900,7 @@ def _test():
counter
=
0
while
counter
<
self
.
quota
:
counter
=
counter
+
1
self
.
queue
.
put
(
"
%
s.
%
d"
%
(
self
.
get_name
()
,
counter
))
self
.
queue
.
put
(
"
%
s.
%
d"
%
(
self
.
name
,
counter
))
_sleep
(
random
()
*
0.00001
)
...
...
@@ -931,7 +925,7 @@ def _test():
P
=
[]
for
i
in
range
(
NP
):
t
=
ProducerThread
(
Q
,
NI
)
t
.
setName
(
"Producer-
%
d"
%
(
i
+
1
))
t
.
name
=
(
"Producer-
%
d"
%
(
i
+
1
))
P
.
append
(
t
)
C
=
ConsumerThread
(
Q
,
NI
*
NP
)
for
t
in
P
:
...
...
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