File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 9
9
10
10
#define MODULE_DOC PyDoc_STR("Fast coverage tracer.")
11
11
12
- static int module_loaded = 0 ;
12
+ static BOOL module_inited = FALSE;
13
+ static PyMutex modinit_mutex = {0 };
13
14
14
15
static int
15
16
tracer_exec (PyObject * mod )
16
17
{
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 ;
22
22
}
23
- module_loaded = 1 ;
24
23
25
24
if (CTracer_intern_strings () < 0 ) {
26
25
return -1 ;
@@ -52,6 +51,9 @@ tracer_exec(PyObject *mod)
52
51
return -1 ;
53
52
}
54
53
54
+ module_inited = TRUE;
55
+ PyMutex_Unlock (& modinit_mutex );
56
+
55
57
return 0 ;
56
58
}
57
59
You can’t perform that action at this time.
0 commit comments