Skip to content

Commit 5ef2dc7

Browse files
Fixed _PyMem_DebugMalloc: Python memory allocator called without holding the GIL
1 parent db2e616 commit 5ef2dc7

5 files changed

Lines changed: 326 additions & 286 deletions

File tree

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,15 @@ PS > python -m pip install .
8383
- `.\.venv\Scripts\Activate.ps1`
8484
- Install dependencies:
8585
- `python -m pip install -r requirements.txt`
86-
- Build in debug (`-g` flag):
87-
- `python setup.py build -g`
88-
- Install into our virtual environment:
89-
- `python setup.py install --force`
86+
- Set DEBUG environment variable:
87+
- $env:DEBUG = "1"
88+
- Build the extension:
89+
- `python_d setup.py build --debug install --force`
90+
- OUTDATED:
91+
- Build in debug (`-g` flag):
92+
- `python setup.py build -g`
93+
- Install into our virtual environment:
94+
- `python setup.py install --force`
9095
- Inside visual studio code:
9196
- Open the root python_ics directory
9297
- `code C:\Path\To\python_ics`

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description = "Python wrapper for interfacing to IntrepidCS Hardware."
77
keywords = ["intrepidcs", "CAN", "Ethernet", "Automotive", "ICS"]
88
readme = { file = "README.md", content-type = "text/markdown" }
99
requires-python = ">=3.9"
10-
license = "MIT"
10+
license = { file = "LICENSE.md" }
1111
classifiers = [
1212
"Development Status :: 5 - Production/Stable",
1313
"Intended Audience :: Developers",

setup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ def run(self):
6969

7070
def get_ics_extension_compiler_arguments() -> List[str]:
7171
"""Return a list of compiler arguments to append for compiling the ics extension module"""
72+
# Debug arguments
73+
is_debug = True if os.environ.get("DEBUG") else False
7274
# gcc and clang arguments
7375
GCC_COMPILE_ARGS = [
7476
"-Wno-unknown-pragmas",
7577
]
78+
if is_debug:
79+
print("NOTICE: Building for DEBUG!")
80+
GCC_COMPILE_ARGS.extend(["-g", "-O0"])
7681
# Set compiler flags here
7782
if "WINDOWS" in platform.system().upper():
7883
compile_args = [
@@ -86,6 +91,8 @@ def get_ics_extension_compiler_arguments() -> List[str]:
8691
"/wd5045",
8792
"/std:c++17",
8893
]
94+
if is_debug:
95+
compile_args.extend(["CL=/Zi", "/Od", "/DEBUG"])
8996
# mingw and clang python builds won't have MSC in the version string
9097
if "MSC" not in sys.version:
9198
compile_args = GCC_COMPILE_ARGS

src/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,14 @@ extern "C"
6969

7070
PyMODINIT_FUNC PyInit_ics(void)
7171
{
72-
initialize_ics_library();
73-
7472
PyObject* module = PyModule_Create(&IcsModule);
75-
7673
if (!module) {
7774
return module;
7875
}
7976
PyDateTime_IMPORT;
8077

78+
initialize_ics_library();
79+
8180
#ifdef Py_GIL_DISABLED
8281
// Enable the experimental free threaded introduced in 3.13
8382
PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);

0 commit comments

Comments
 (0)