bpo-34228: Allow PYTHONTRACEMALLOC=0 (GH-8467) · pythoncapi/cpython@60b04c9 · GitHub
Skip to content

Commit 60b04c9

Browse files
authored
bpo-34228: Allow PYTHONTRACEMALLOC=0 (pythonGH-8467)
PYTHONTRACEMALLOC=0 environment variable and -X tracemalloc=0 command line option are now allowed to disable explicitly tracemalloc at startup.
1 parent 96d1e69 commit 60b04c9

4 files changed

Lines changed: 30 additions & 9 deletions

File tree

Include/pystate.h

Lines changed: 1 addition & 0 deletions

Lib/test/test_tracemalloc.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616

1717
EMPTY_STRING_SIZE = sys.getsizeof(b'')
18+
INVALID_NFRAME = (-1, 2**30)
1819

1920

2021
def get_frames(nframe, lineno_delta):
@@ -833,6 +834,13 @@ def test_env_var_ignored_with_E(self):
833834
stdout = stdout.rstrip()
834835
self.assertEqual(stdout, b'False')
835836

837+
def test_env_var_disabled(self):
838+
# tracing at startup
839+
code = 'import tracemalloc; print(tracemalloc.is_tracing())'
840+
ok, stdout, stderr = assert_python_ok('-c', code, PYTHONTRACEMALLOC='0')
841+
stdout = stdout.rstrip()
842+
self.assertEqual(stdout, b'False')
843+
836844
def test_env_var_enabled_at_startup(self):
837845
# tracing at startup
838846
code = 'import tracemalloc; print(tracemalloc.is_tracing())'
@@ -861,7 +869,7 @@ def check_env_var_invalid(self, nframe):
861869

862870

863871
def test_env_var_invalid(self):
864-
for nframe in (-1, 0, 2**30):
872+
for nframe in INVALID_NFRAME:
865873
with self.subTest(nframe=nframe):
866874
self.check_env_var_invalid(nframe)
867875

@@ -889,7 +897,7 @@ def check_sys_xoptions_invalid(self, nframe):
889897
self.fail(f"unexpeced output: {stderr!a}")
890898

891899
def test_sys_xoptions_invalid(self):
892-
for nframe in (-1, 0, 2**30):
900+
for nframe in INVALID_NFRAME:
893901
with self.subTest(nframe=nframe):
894902
self.check_sys_xoptions_invalid(nframe)
895903

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tracemalloc: PYTHONTRACEMALLOC=0 environment variable and -X tracemalloc=0
2+
command line option are now allowed to disable explicitly tracemalloc at
3+
startup.

Modules/main.c

Lines changed: 16 additions & 7 deletions

0 commit comments

Comments
 (0)