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

Function collect_in_thread

Lib/test/test_weakref.py:85–103  ·  view source on GitHub ↗

Ensure GC collections happen in a different thread, at a high frequency.

(period=0.005)

Source from the content-addressed store, hash-verified

83
84@contextlib.contextmanager
85def collect_in_thread(period=0.005):
86 """
87 Ensure GC collections happen in a different thread, at a high frequency.
88 """
89 please_stop = False
90
91 def collect():
92 while not please_stop:
93 time.sleep(period)
94 gc.collect()
95
96 with support.disable_gc():
97 t = threading.Thread(target=collect)
98 t.start()
99 try:
100 yield
101 finally:
102 please_stop = True
103 t.join()
104
105
106class ReferencesTestCase(TestBase):

Calls 2

startMethod · 0.95
joinMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…