mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	give the threading API PEP 8 names
This commit is contained in:
		
							parent
							
								
									32c2e41c82
								
							
						
					
					
						commit
						0fbcf69455
					
				
					 20 changed files with 127 additions and 126 deletions
				
			
		| 
						 | 
				
			
			@ -34,7 +34,7 @@ def run(self):
 | 
			
		|||
        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,14 +45,14 @@ def run(self):
 | 
			
		|||
 | 
			
		||||
            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):
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -73,7 +73,7 @@ def test_various_ops(self):
 | 
			
		|||
        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()
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -81,8 +81,8 @@ def test_various_ops(self):
 | 
			
		|||
            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'
 | 
			
		||||
| 
						 | 
				
			
			@ -172,7 +172,7 @@ def run(self):
 | 
			
		|||
                    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"
 | 
			
		||||
| 
						 | 
				
			
			@ -258,12 +258,12 @@ def killer():
 | 
			
		|||
                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)
 | 
			
		||||
| 
						 | 
				
			
			@ -348,8 +348,8 @@ def test_semaphore_with_negative_value(self):
 | 
			
		|||
        self.assertRaises(ValueError, threading.Semaphore, value = -sys.maxint)
 | 
			
		||||
 | 
			
		||||
    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()
 | 
			
		||||
| 
						 | 
				
			
			@ -358,7 +358,7 @@ def test_joining_inactive_thread(self):
 | 
			
		|||
    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