Python thread.allocate() Examples

The following are 1 code examples of thread.allocate(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module thread , or try the search function .
Example #1
Source File: test_thread.py    From ironpython2 with Apache License 2.0 4 votes vote down vote up
def test_start_new_thread(self):
        #--Sanity
        global CALLED
        CALLED = False
        
        lock = thread.allocate()
        def tempFunc(mykw_param=1):
            global CALLED
            lock.acquire()
            CALLED = mykw_param
            lock.release()
            thread.exit_thread()
            
        id = thread.start_new_thread(tempFunc, (), {"mykw_param":7})
        while CALLED==False:
            print ".",
            time.sleep(0.1)
        self.assertEqual(CALLED, 7)
        
        id = thread.start_new_thread(tempFunc, (), {"mykw_param":8})
        while CALLED!=8:  #Hang forever if this is broken
            print ".",
            time.sleep(0.1)
        
        #--Sanity Negative
        global temp_stderr
        temp_stderr = ""
        se = sys.stderr
        
        class myStdOut:
            def write(self, text): 
                global temp_stderr
                temp_stderr += text

        try:
            sys.stderr = myStdOut()
            
            id = thread.start_new_thread(tempFunc, (), {"my_misspelled_kw_param":9})
            time.sleep(1)
            se.flush()
        finally:
            sys.stderr = se
        
        self.assertEqual(CALLED, 8)
        self.assertTrue("tempFunc() got an unexpected keyword argument 'my_misspelled_kw_param" in temp_stderr)