The Python documentation does not adequately describe how to lock the GIL for embedded Python 3.x. After some trial and error and lots of searching, I was finally able to understand how the GIL should be locked. The GIL must be locked when any Python code/script is called otherwise you’ll end up with lots of access violations.
In your initialization function:
In any function that calls Python:
In your Python finalization function: