Could you try to create a cuda coredump using the code, which is failing quickly via:
export CUDA_ENABLE_COREDUMP_ON_EXCEPTION=1
python script.py args

Once the IMA is triggered, a file should have been created in the working directory, which you could use to get a valid stacktrace.
Running with cuda-gdb might also work, but since you are seeing different behavior when printing stuff, it could point towards a potential race condition, so I would try to avoid slowing down the code.