~pythonregexp2.7/python/issue2636-09-01+10

« back to all changes in this revision

Viewing changes to Lib/test/test_threading_local.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-22 21:39:45 UTC
  • mfrom: (39055.1.33 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080922213945-23717m5eiqpamcyn
Merged in changes from the Single-Loop Engine branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
        deadlist = [weak for weak in weaklist if weak() is None]
43
43
        self.assert_(len(deadlist) in (n-1, n), (n, len(deadlist)))
44
44
 
 
45
    def test_derived(self):
 
46
        # Issue 3088: if there is a threads switch inside the __init__
 
47
        # of a threading.local derived class, the per-thread dictionary
 
48
        # is created but not correctly set on the object.
 
49
        # The first member set may be bogus.
 
50
        import time
 
51
        class Local(threading.local):
 
52
            def __init__(self):
 
53
                time.sleep(0.01)
 
54
        local = Local()
 
55
 
 
56
        def f(i):
 
57
            local.x = i
 
58
            # Simply check that the variable is correctly set
 
59
            self.assertEqual(local.x, i)
 
60
 
 
61
        threads= []
 
62
        for i in range(10):
 
63
            t = threading.Thread(target=f, args=(i,))
 
64
            t.start()
 
65
            threads.append(t)
 
66
 
 
67
        for t in threads:
 
68
            t.join()
 
69
 
 
70
 
45
71
def test_main():
46
72
    suite = unittest.TestSuite()
47
73
    suite.addTest(DocTestSuite('_threading_local'))