It’s hard to tell where this bug is coming from and a minimal code snippet would be helpful.
Since you are already running into this issue, you could also use gdb to get the stack trace and post it here, so that we could have a look:
$ gdb --args python my_script.py
...
Reading symbols from python...done.
(gdb) run
...
(gdb) backtrace
...