Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:57

0001 import threading
0002 
0003 from pybind11_tests import thread as m
0004 
0005 
0006 class Thread(threading.Thread):
0007     def __init__(self, fn):
0008         super().__init__()
0009         self.fn = fn
0010         self.e = None
0011 
0012     def run(self):
0013         try:
0014             for i in range(10):
0015                 self.fn(i, i)
0016         except Exception as e:
0017             self.e = e
0018 
0019     def join(self):
0020         super().join()
0021         if self.e:
0022             raise self.e
0023 
0024 
0025 def test_implicit_conversion():
0026     a = Thread(m.test)
0027     b = Thread(m.test)
0028     c = Thread(m.test)
0029     for x in [a, b, c]:
0030         x.start()
0031     for x in [c, b, a]:
0032         x.join()
0033 
0034 
0035 def test_implicit_conversion_no_gil():
0036     a = Thread(m.test_no_gil)
0037     b = Thread(m.test_no_gil)
0038     c = Thread(m.test_no_gil)
0039     for x in [a, b, c]:
0040         x.start()
0041     for x in [c, b, a]:
0042         x.join()