8000 gh-134604: Fix tracemalloc crash with subinterpreters by emmatyping · Pull Request #134667 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-134604: Fix tracemalloc crash with subinterpreters #134667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for subinterpreters + tracemalloc
  • Loading branch information
emmatyping committed May 25, 2025
commit daebaff12693e34b436028926411562c0f04d345
30 changes: 30 additions & 0 deletions Lib/test/test__interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pickle
from textwrap import dedent
import threading
import tracemalloc
import unittest

from test import support
Expand Down Expand Up @@ -1098,5 +1099,34 @@ def script(spam, /):
_interpreters.run_func(self.id, script)


class TestTracemallocWithInterpreters(TestBase):
def setUp(self):
if tracemalloc.is_tracing():
self.skipTest("tracemalloc must be stopped before the test")

tracemalloc.start(1)

def tearDown(self):
tracemalloc.stop()
super().tearDown()

def test_trace_interp_start_frames(self):
interpid = _interpreters.create()
# check that tracing captures frames created by the new interpreter
self.assertNotEqual(
tracemalloc.take_snapshot().statistics("filename"),
[]
)
_interpreters.destroy(interpid)

def test_trace_interp_frames(self):
interpid = _interpreters.create()
_interpreters.run_string(interpid, "def f(): ...")
stats = tracemalloc.take_snapshot().statistics("filename")
# check that the last frame is the string run in the interpreter
self.assertEqual(stats[-1].traceback._frames[0][0], "<string>")
_interpreters.destroy(interpid)


if __name__ == '__main__':
unittest.main()
0