Skip to content

Commit 8381ea7

Browse files
committed
fix: allow module to be imported twice in the same process
1 parent 6beea4b commit 8381ea7

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

coverage/ctracer/module.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,14 @@
99

1010
#define MODULE_DOC PyDoc_STR("Fast coverage tracer.")
1111

12-
static int module_loaded = 0;
12+
static BOOL module_inited = FALSE;
1313

1414
static int
1515
tracer_exec(PyObject *mod)
1616
{
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;
17+
if (module_inited) {
18+
return 0;
2219
}
23-
module_loaded = 1;
2420

2521
if (CTracer_intern_strings() < 0) {
2622
return -1;
@@ -52,6 +48,7 @@ tracer_exec(PyObject *mod)
5248
return -1;
5349
}
5450

51+
module_inited = TRUE;
5552
return 0;
5653
}
5754

0 commit comments

Comments
 (0)