Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
11cf7d7c
Commit
11cf7d7c
authored
Jan 17, 2012
by
Ralf Schmitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pep8 cleanup test_threading_2.py
parent
63e7f1f9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
+19
-6
greentest/test_threading_2.py
greentest/test_threading_2.py
+19
-6
No files found.
greentest/test_threading_2.py
View file @
11cf7d7c
...
@@ -44,16 +44,22 @@ import weakref
...
@@ -44,16 +44,22 @@ import weakref
import
lock_tests
import
lock_tests
# A trivial mutable counter.
# A trivial mutable counter.
class
Counter
(
object
):
class
Counter
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
value
=
0
self
.
value
=
0
def
inc
(
self
):
def
inc
(
self
):
self
.
value
+=
1
self
.
value
+=
1
def
dec
(
self
):
def
dec
(
self
):
self
.
value
-=
1
self
.
value
-=
1
def
get
(
self
):
def
get
(
self
):
return
self
.
value
return
self
.
value
class
TestThread
(
threading
.
Thread
):
class
TestThread
(
threading
.
Thread
):
def
__init__
(
self
,
name
,
testcase
,
sema
,
mutex
,
nrunning
):
def
__init__
(
self
,
name
,
testcase
,
sema
,
mutex
,
nrunning
):
threading
.
Thread
.
__init__
(
self
,
name
=
name
)
threading
.
Thread
.
__init__
(
self
,
name
=
name
)
...
@@ -86,6 +92,7 @@ class TestThread(threading.Thread):
...
@@ -86,6 +92,7 @@ class TestThread(threading.Thread):
print
'%s is finished. %d tasks are running'
%
(
print
'%s is finished. %d tasks are running'
%
(
self
.
name
,
self
.
nrunning
.
get
())
self
.
name
,
self
.
nrunning
.
get
())
class
ThreadTests
(
unittest
.
TestCase
):
class
ThreadTests
(
unittest
.
TestCase
):
# Create a bunch of threads, let each do some work, wait until all are
# Create a bunch of threads, let each do some work, wait until all are
...
@@ -103,7 +110,7 @@ class ThreadTests(unittest.TestCase):
...
@@ -103,7 +110,7 @@ class ThreadTests(unittest.TestCase):
threads
=
[]
threads
=
[]
for
i
in
range
(
NUMTASKS
):
for
i
in
range
(
NUMTASKS
):
t
=
TestThread
(
"<thread %d>"
%
i
,
self
,
sema
,
mutex
,
numrunning
)
t
=
TestThread
(
"<thread %d>"
%
i
,
self
,
sema
,
mutex
,
numrunning
)
threads
.
append
(
t
)
threads
.
append
(
t
)
if
hasattr
(
t
,
'ident'
):
if
hasattr
(
t
,
'ident'
):
self
.
failUnlessEqual
(
t
.
ident
,
None
)
self
.
failUnlessEqual
(
t
.
ident
,
None
)
...
@@ -127,6 +134,7 @@ class ThreadTests(unittest.TestCase):
...
@@ -127,6 +134,7 @@ class ThreadTests(unittest.TestCase):
def test_ident_of_no_threading_threads(self):
def test_ident_of_no_threading_threads(self):
# The ident still must work for the main thread and dummy threads.
# The ident still must work for the main thread and dummy threads.
self.assertFalse(threading.currentThread().ident is None)
self.assertFalse(threading.currentThread().ident is None)
def f():
def f():
ident.append(threading.currentThread().ident)
ident.append(threading.currentThread().ident)
done.set()
done.set()
...
@@ -220,7 +228,7 @@ class ThreadTests(unittest.TestCase):
...
@@ -220,7 +228,7 @@ class ThreadTests(unittest.TestCase):
worker_saw_exception.set()
worker_saw_exception.set()
t = Worker()
t = Worker()
t.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()
t.start()
if verbose:
if verbose:
print "
started
worker
thread
"
print "
started
worker
thread
"
...
@@ -241,7 +249,7 @@ class ThreadTests(unittest.TestCase):
...
@@ -241,7 +249,7 @@ class ThreadTests(unittest.TestCase):
if verbose:
if verbose:
print " attempting to raise asynch exception in worker"
print " attempting to raise asynch exception in worker"
result = set_async_exc(ctypes.c_long(t.id), exception)
result = set_async_exc(ctypes.c_long(t.id), exception)
self.assertEqual(result, 1) # one thread state modified
self.assertEqual(result, 1)
# one thread state modified
if verbose:
if verbose:
print " waiting for worker to say it caught the exception"
print " waiting for worker to say it caught the exception"
worker_saw_exception.wait(timeout=10)
worker_saw_exception.wait(timeout=10)
...
@@ -393,7 +401,7 @@ class ThreadTests(unittest.TestCase):
...
@@ -393,7 +401,7 @@ class ThreadTests(unittest.TestCase):
self
.
should_raise
=
should_raise
self
.
should_raise
=
should_raise
self
.
thread
=
threading
.
Thread
(
target
=
self
.
_run
,
self
.
thread
=
threading
.
Thread
(
target
=
self
.
_run
,
args
=
(
self
,),
args
=
(
self
,),
kwargs
=
{
'yet_another'
:
self
})
kwargs
=
{
'yet_another'
:
self
})
self
.
thread
.
start
()
self
.
thread
.
start
()
def
_run
(
self
,
other_ref
,
yet_another
):
def
_run
(
self
,
other_ref
,
yet_another
):
...
@@ -450,7 +458,6 @@ class ThreadJoinOnShutdown(unittest.TestCase):
...
@@ -450,7 +458,6 @@ class ThreadJoinOnShutdown(unittest.TestCase):
"""
"""
self
.
_run_and_join
(
script
)
self
.
_run_and_join
(
script
)
def
test_2_join_in_forked_process
(
self
):
def
test_2_join_in_forked_process
(
self
):
# Like the test above, but from a forked interpreter
# Like the test above, but from a forked interpreter
import
os
import
os
...
@@ -512,7 +519,7 @@ class ThreadingExceptionTests(unittest.TestCase):
...
@@ -512,7 +519,7 @@ class ThreadingExceptionTests(unittest.TestCase):
def
test_joining_current_thread
(
self
):
def
test_joining_current_thread
(
self
):
current_thread
=
threading
.
current_thread
()
current_thread
=
threading
.
current_thread
()
self
.
assertRaises
(
RuntimeError
,
current_thread
.
join
)
;
self
.
assertRaises
(
RuntimeError
,
current_thread
.
join
)
def
test_joining_inactive_thread
(
self
):
def
test_joining_inactive_thread
(
self
):
thread
=
threading
.
Thread
()
thread
=
threading
.
Thread
()
...
@@ -527,22 +534,28 @@ class ThreadingExceptionTests(unittest.TestCase):
...
@@ -527,22 +534,28 @@ class ThreadingExceptionTests(unittest.TestCase):
class
LockTests
(
lock_tests
.
LockTests
):
class
LockTests
(
lock_tests
.
LockTests
):
locktype
=
staticmethod
(
threading
.
Lock
)
locktype
=
staticmethod
(
threading
.
Lock
)
class
RLockTests
(
lock_tests
.
RLockTests
):
class
RLockTests
(
lock_tests
.
RLockTests
):
locktype
=
staticmethod
(
threading
.
RLock
)
locktype
=
staticmethod
(
threading
.
RLock
)
class
EventTests
(
lock_tests
.
EventTests
):
class
EventTests
(
lock_tests
.
EventTests
):
eventtype
=
staticmethod
(
threading
.
Event
)
eventtype
=
staticmethod
(
threading
.
Event
)
class
ConditionAsRLockTests
(
lock_tests
.
RLockTests
):
class
ConditionAsRLockTests
(
lock_tests
.
RLockTests
):
# An Condition uses an RLock by default and exports its API.
# An Condition uses an RLock by default and exports its API.
locktype
=
staticmethod
(
threading
.
Condition
)
locktype
=
staticmethod
(
threading
.
Condition
)
class
ConditionTests
(
lock_tests
.
ConditionTests
):
class
ConditionTests
(
lock_tests
.
ConditionTests
):
condtype
=
staticmethod
(
threading
.
Condition
)
condtype
=
staticmethod
(
threading
.
Condition
)
class
SemaphoreTests
(
lock_tests
.
SemaphoreTests
):
class
SemaphoreTests
(
lock_tests
.
SemaphoreTests
):
semtype
=
staticmethod
(
threading
.
Semaphore
)
semtype
=
staticmethod
(
threading
.
Semaphore
)
class
BoundedSemaphoreTests
(
lock_tests
.
BoundedSemaphoreTests
):
class
BoundedSemaphoreTests
(
lock_tests
.
BoundedSemaphoreTests
):
semtype
=
staticmethod
(
threading
.
BoundedSemaphore
)
semtype
=
staticmethod
(
threading
.
BoundedSemaphore
)
...
...
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