| 1042 | support.check_sizeof(self, q, basesize + struct.calcsize(1024 * 'P')) |
| 1043 | |
| 1044 | def test_reentrancy(self): |
| 1045 | # bpo-14976: put() may be called reentrantly in an asynchronous |
| 1046 | # callback. |
| 1047 | q = self.q |
| 1048 | gen = itertools.count() |
| 1049 | N = 10000 |
| 1050 | results = [] |
| 1051 | |
| 1052 | # This test exploits the fact that __del__ in a reference cycle |
| 1053 | # can be called any time the GC may run. |
| 1054 | |
| 1055 | class Circular(object): |
| 1056 | def __init__(self): |
| 1057 | self.circular = self |
| 1058 | |
| 1059 | def __del__(self): |
| 1060 | q.put(next(gen)) |
| 1061 | |
| 1062 | while True: |
| 1063 | o = Circular() |
| 1064 | q.put(next(gen)) |
| 1065 | del o |
| 1066 | results.append(q.get()) |
| 1067 | if results[-1] >= N: |
| 1068 | break |
| 1069 | |
| 1070 | self.assertEqual(results, list(range(N + 1))) |
| 1071 | |
| 1072 | |
| 1073 | if __name__ == "__main__": |