2023-04-18 16:11:43 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2022-06-20 22:59:56 +00:00
|
|
|
import threading
|
|
|
|
|
|
|
|
from pybind11_tests import thread as m
|
|
|
|
|
|
|
|
|
|
|
|
class Thread(threading.Thread):
|
|
|
|
def __init__(self, fn):
|
2023-04-18 16:11:43 +00:00
|
|
|
super(Thread, self).__init__()
|
2022-06-20 22:59:56 +00:00
|
|
|
self.fn = fn
|
|
|
|
self.e = None
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
try:
|
|
|
|
for i in range(10):
|
|
|
|
self.fn(i, i)
|
|
|
|
except Exception as e:
|
|
|
|
self.e = e
|
|
|
|
|
|
|
|
def join(self):
|
2023-04-18 16:11:43 +00:00
|
|
|
super(Thread, self).join()
|
2022-06-20 22:59:56 +00:00
|
|
|
if self.e:
|
|
|
|
raise self.e
|
|
|
|
|
|
|
|
|
|
|
|
def test_implicit_conversion():
|
|
|
|
a = Thread(m.test)
|
|
|
|
b = Thread(m.test)
|
|
|
|
c = Thread(m.test)
|
|
|
|
for x in [a, b, c]:
|
|
|
|
x.start()
|
|
|
|
for x in [c, b, a]:
|
|
|
|
x.join()
|
|
|
|
|
|
|
|
|
|
|
|
def test_implicit_conversion_no_gil():
|
|
|
|
a = Thread(m.test_no_gil)
|
|
|
|
b = Thread(m.test_no_gil)
|
|
|
|
c = Thread(m.test_no_gil)
|
|
|
|
for x in [a, b, c]:
|
|
|
|
x.start()
|
|
|
|
for x in [c, b, a]:
|
|
|
|
x.join()
|