Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
95016e71
Commit
95016e71
authored
Jan 19, 2008
by
Christian Heimes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update for threading.local test.
parent
71a0451f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
2 deletions
+18
-2
Lib/test/test_threading_local.py
Lib/test/test_threading_local.py
+18
-2
No files found.
Lib/test/test_threading_local.py
View file @
95016e71
...
...
@@ -3,6 +3,7 @@ from doctest import DocTestSuite
from
test
import
test_support
import
threading
import
weakref
import
gc
class
Weak
(
object
):
pass
...
...
@@ -13,19 +14,34 @@ def target(local, weaklist):
weaklist
.
append
(
weakref
.
ref
(
weak
))
class
ThreadingLocalTest
(
unittest
.
TestCase
):
def
test_local_refs
(
self
):
self
.
_local_refs
(
20
)
self
.
_local_refs
(
50
)
self
.
_local_refs
(
100
)
def
_local_refs
(
self
,
n
):
local
=
threading
.
local
()
weaklist
=
[]
n
=
20
for
i
in
range
(
n
):
t
=
threading
.
Thread
(
target
=
target
,
args
=
(
local
,
weaklist
))
t
.
start
()
t
.
join
()
del
t
gc
.
collect
()
self
.
assertEqual
(
len
(
weaklist
),
n
)
# XXX threading.local keeps the local of the last stopped thread alive.
deadlist
=
[
weak
for
weak
in
weaklist
if
weak
()
is
None
]
# XXX threading.local keeps the local of the last stopped thread alive
self
.
assertEqual
(
len
(
deadlist
),
n
-
1
)
# Assignment to the same thread local frees it sometimes (!)
local
.
someothervar
=
None
gc
.
collect
()
deadlist
=
[
weak
for
weak
in
weaklist
if
weak
()
is
None
]
self
.
assert_
(
len
(
deadlist
)
in
(
n
-
1
,
n
),
(
n
,
len
(
deadlist
)))
def
test_main
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
DocTestSuite
(
'_threading_local'
))
...
...
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