You can try attaching strace to the process and redirect output to a file.
However, I do not know python well. I can read through the code and understand what It does. There may be known issues with the language it’s self which could be causing this behavior. Through either the library you’re using, or in your own code. e.g. by using bad coding “technique”. Again I know almost nothing about the language it’s self.
You may wish to start researching on known memory leaks when using python. While strace is running attached to your script PID.