Skip to content

Commit 2f49e09

Browse files
committed
Fix _tracemalloc start/stop
Issue python#26588: Fix _tracemalloc start/stop: don't play with the reentrant flag. set_reentrant(1) fails with an assertion error if tracemalloc_init() is called first in a thread A and tracemalloc_start() is called second in a thread B. The tracemalloc is imported in a thread A. Importing the module calls tracemalloc_init(). tracemalloc.start() is called in a thread B.
1 parent d6990d2 commit 2f49e09

1 file changed

Lines changed: 0 additions & 14 deletions

File tree

‎Modules/_tracemalloc.c‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -740,10 +740,6 @@ tracemalloc_clear_traces(void)
740740
assert(PyGILState_Check());
741741
#endif
742742

743-
/* Disable also reentrant calls to tracemalloc_malloc() to not add a new
744-
trace while we are clearing traces */
745-
assert(get_reentrant());
746-
747743
TABLES_LOCK();
748744
_Py_hashtable_clear(tracemalloc_traces);
749745
tracemalloc_traced_memory = 0;
@@ -823,11 +819,6 @@ tracemalloc_init(void)
823819
tracemalloc_empty_traceback.frames[0].lineno = 0;
824820
tracemalloc_empty_traceback.hash = traceback_hash(&tracemalloc_empty_traceback);
825821

826-
/* Disable tracing allocations until hooks are installed. Set
827-
also the reentrant flag to detect bugs: fail with an assertion error
828-
if set_reentrant(1) is called while tracing is disabled. */
829-
set_reentrant(1);
830-
831822
tracemalloc_config.initialized = TRACEMALLOC_INITIALIZED;
832823
return 0;
833824
}
@@ -912,7 +903,6 @@ tracemalloc_start(int max_nframe)
912903

913904
/* everything is ready: start tracing Python memory allocations */
914905
tracemalloc_config.tracing = 1;
915-
set_reentrant(0);
916906

917907
return 0;
918908
}
@@ -926,10 +916,6 @@ tracemalloc_stop(void)
926916
/* stop tracing Python memory allocations */
927917
tracemalloc_config.tracing = 0;
928918

929-
/* set the reentrant flag to detect bugs: fail with an assertion error if
930-
set_reentrant(1) is called while tracing is disabled. */
931-
set_reentrant(1);
932-
933919
/* unregister the hook on memory allocators */
934920
#ifdef TRACE_RAW_MALLOC
935921
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &allocators.raw);

0 commit comments

Comments
 (0)