mirror of
https://github.com/python/cpython.git
synced 2025-07-16 07:45:20 +00:00
Merged revisions 64125 via svnmerge from
svn+ssh://pythondev@svn.python.org/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 ........
This commit is contained in:
parent
559e5d7f4d
commit
672b8031a8
20 changed files with 126 additions and 131 deletions
|
@ -34,7 +34,7 @@ class TestThread(threading.Thread):
|
|||
delay = random.random() / 10000.0
|
||||
if verbose:
|
||||
print('task %s will run for %.1f usec' %
|
||||
(self.getName(), delay * 1e6))
|
||||
(self.get_name(), delay * 1e6))
|
||||
|
||||
with self.sema:
|
||||
with self.mutex:
|
||||
|
@ -45,13 +45,15 @@ class TestThread(threading.Thread):
|
|||
|
||||
time.sleep(delay)
|
||||
if verbose:
|
||||
print('task', self.getName(), 'done')
|
||||
print('task', self.get_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.getName(), self.nrunning.get()))
|
||||
(self.get_name(), self.nrunning.get()))
|
||||
|
||||
|
||||
class ThreadTests(unittest.TestCase):
|
||||
|
||||
|
@ -72,7 +74,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.getIdent(), None)
|
||||
self.failUnlessEqual(t.get_ident(), None)
|
||||
self.assert_(re.match('<TestThread\(.*, initial\)>', repr(t)))
|
||||
t.start()
|
||||
|
||||
|
@ -80,8 +82,8 @@ class ThreadTests(unittest.TestCase):
|
|||
print('waiting for all tasks to complete')
|
||||
for t in threads:
|
||||
t.join(NUMTASKS)
|
||||
self.assert_(not t.isAlive())
|
||||
self.failIfEqual(t.getIdent(), 0)
|
||||
self.assert_(not t.is_alive())
|
||||
self.failIfEqual(t.get_ident(), 0)
|
||||
self.assert_(re.match('<TestThread\(.*, \w+ -?\d+\)>', repr(t)))
|
||||
if verbose:
|
||||
print('all tasks done')
|
||||
|
@ -171,7 +173,7 @@ class ThreadTests(unittest.TestCase):
|
|||
worker_saw_exception.set()
|
||||
|
||||
t = Worker()
|
||||
t.setDaemon(True) # so if this fails, we don't hang Python at shutdown
|
||||
t.set_daemon(True) # so if this fails, we don't hang Python at shutdown
|
||||
t.start()
|
||||
if verbose:
|
||||
print(" started worker thread")
|
||||
|
@ -257,12 +259,12 @@ class ThreadTests(unittest.TestCase):
|
|||
print('program blocked; aborting')
|
||||
os._exit(2)
|
||||
t = threading.Thread(target=killer)
|
||||
t.setDaemon(True)
|
||||
t.set_daemon(True)
|
||||
t.start()
|
||||
|
||||
# This is the trace function
|
||||
def func(frame, event, arg):
|
||||
threading.currentThread()
|
||||
threading.current_thread()
|
||||
return func
|
||||
|
||||
sys.settrace(func)
|
||||
|
@ -347,8 +349,8 @@ class ThreadingExceptionTests(unittest.TestCase):
|
|||
self.assertRaises(ValueError, threading.Semaphore, value = -sys.maxsize)
|
||||
|
||||
def test_joining_current_thread(self):
|
||||
currentThread = threading.currentThread()
|
||||
self.assertRaises(RuntimeError, currentThread.join);
|
||||
current_thread = threading.current_thread()
|
||||
self.assertRaises(RuntimeError, current_thread.join);
|
||||
|
||||
def test_joining_inactive_thread(self):
|
||||
thread = threading.Thread()
|
||||
|
@ -357,7 +359,7 @@ class ThreadingExceptionTests(unittest.TestCase):
|
|||
def test_daemonize_active_thread(self):
|
||||
thread = threading.Thread()
|
||||
thread.start()
|
||||
self.assertRaises(RuntimeError, thread.setDaemon, True)
|
||||
self.assertRaises(RuntimeError, thread.set_daemon, True)
|
||||
|
||||
|
||||
def test_main():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue