| 1032 | self.assertIs(self.type2test, self.queue.SimpleQueue) |
| 1033 | |
| 1034 | def test_reentrancy(self): |
| 1035 | # bpo-14976: put() may be called reentrantly in an asynchronous |
| 1036 | # callback. |
| 1037 | q = self.q |
| 1038 | gen = itertools.count() |
| 1039 | N = 10000 |
| 1040 | results = [] |
| 1041 | |
| 1042 | # This test exploits the fact that __del__ in a reference cycle |
| 1043 | # can be called any time the GC may run. |
| 1044 | |
| 1045 | class Circular(object): |
| 1046 | def __init__(self): |
| 1047 | self.circular = self |
| 1048 | |
| 1049 | def __del__(self): |
| 1050 | q.put(next(gen)) |
| 1051 | |
| 1052 | while True: |
| 1053 | o = Circular() |
| 1054 | q.put(next(gen)) |
| 1055 | del o |
| 1056 | results.append(q.get()) |
| 1057 | if results[-1] >= N: |
| 1058 | break |
| 1059 | |
| 1060 | self.assertEqual(results, list(range(N + 1))) |
| 1061 | |
| 1062 | |
| 1063 | if __name__ == "__main__": |