Skip to content

Commit

Permalink
Add test for cleaning up tlbc in correct place, not old emacs buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mpage committed Oct 14, 2024
1 parent 70ce0fe commit f512353
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Lib/test/test_thread_local_bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,43 @@ def f(q):
""")
assert_python_ok("-X", "tlbc=1", "-c", code)

def test_tlbc_cleanup(self):
code = textwrap.dedent("""
import gc
import sys
import threading
def f(barrier, callee):
barrier.wait()
return callee()
# Define callee dynamically so that the module body's constants don't
# hold a strong reference to the code object.
ns = {}
exec('def func(): return 42', globals=ns)
callee = ns.pop('func')
# Create 5 copies of callee's bytecode
threads = []
barrier = threading.Barrier(5)
for _ in range(barrier.parties):
t = threading.Thread(target=f, args=(barrier, callee))
t.start()
threads.append(t)
for t in threads:
t.join()
# Destroy the only reference to callee's code object. All the tlbc
# copies should be destroyed when the code object is destroyed in the
# call to gc.collect below.
before = sys._get_tlbc_blocks()
callee.__code__ = f.__code__
gc.collect()
after = sys._get_tlbc_blocks()
assert (before - after) == len(threads)
""")
assert_python_ok("-X", "tlbc=1", "-c", code)


if __name__ == "__main__":
unittest.main()

0 comments on commit f512353

Please sign in to comment.