MCPcopy Index your code
hub / github.com/python/cpython / test_reentrancy

Method test_reentrancy

Lib/test/test_queue.py:1044–1070  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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
1073if __name__ == "__main__":

Callers

nothing calls this directly

Calls 7

CircularClass · 0.85
listClass · 0.85
countMethod · 0.45
putMethod · 0.45
appendMethod · 0.45
getMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected