File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99
1010#define MODULE_DOC PyDoc_STR("Fast coverage tracer.")
1111
12- static int module_loaded = 0 ;
12+ static BOOL module_inited = FALSE;
13+ static PyMutex modinit_mutex = {0 };
1314
1415static int
1516tracer_exec (PyObject * mod )
1617{
17- // https://docs.python.org/3/howto/isolating-extensions.html#opt-out-limiting-to-one-module-object-per-process
18- if (module_loaded ) {
19- PyErr_SetString (PyExc_ImportError ,
20- "cannot load module more than once per process" );
21- return -1 ;
18+ PyMutex_Lock (& modinit_mutex );
19+ if (module_inited ) {
20+ PyMutex_Unlock (& modinit_mutex );
21+ return 0 ;
2222 }
23- module_loaded = 1 ;
2423
2524 if (CTracer_intern_strings () < 0 ) {
2625 return -1 ;
@@ -52,6 +51,9 @@ tracer_exec(PyObject *mod)
5251 return -1 ;
5352 }
5453
54+ module_inited = TRUE;
55+ PyMutex_Unlock (& modinit_mutex );
56+
5557 return 0 ;
5658}
5759
You can’t perform that action at this time.
0 commit comments