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

Method pop_and_collect

Lib/test/test_weakref.py:2023–2030  ·  view source on GitHub ↗
(lst)

Source from the content-addressed store, hash-verified

2021 exc.append(ex)
2022
2023 def pop_and_collect(lst):
2024 gc_ctr = 0
2025 while lst:
2026 i = random.randint(0, len(lst) - 1)
2027 gc_ctr += 1
2028 lst.pop(i)
2029 if gc_ctr % 10000 == 0:
2030 gc.collect() # just in case
2031
2032 self.assertIn(type_, (weakref.WeakKeyDictionary, weakref.WeakValueDictionary))
2033

Callers

nothing calls this directly

Calls 3

randintMethod · 0.80
popMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected