I live in Terminal sessions. My Terminal never tries to quit.
Now if you have an app like Quitter running and specified it should kill the Terminal after a period of time, or you have some other app that thinks it should kill apps, then Maybe.
Another possibility is if your program consumes all of your disk space and macOS cannot page or swap memory to disk anymore, or your process is becoming a virtual memory hog and causing macOS to use too much memory for virtual memory page tables, then I can see macOS trying to kill Terminal. But generally you get a message about being out of Application Memory.
Again, I have my work computer on 24/7, it never sleeps, and it has Terminal sessions running from right after being booted until it shutdown for macOS software updates that require a restart.
So I would be asking why you have running besides the Terminal and your Python script?
Try booting into Safe mode
http://support.apple.com/kb/ht1564
This will not load any 3rd party additions, it will load some more conservative Apple drivers (may cause screen flicker), and it will clear some kernel caches (a cache is saved data in a form that can speed up a program, but is totally redundant to the original source, and thus can be safely cleared). Booting into Safe mode is just an experiment, but can frequently eliminate any 3rd party interference, or a cached item out-of-sync with the world. (Verify Safe mode via Applications -> Utilities -> System Information -> Software -> Boot Mode -> Safe vs Normal)
You could also consider posting the EtreCheck output
<https://itunes.apple.com/app/etrecheck/id1423715984?ls=1&mt=12>
Click on the Share icon and select "Copy Report"

And then Paste the report as a "Reply" to this thread using an "Additional Text" box.
EtreCheck is a tool that helps Apple Support Community volunteers debug problems without any access to the troubled computers. Debugging problems can be a difficult task even when the machine is in front of you. Attempting it via a discussion forum is extremely difficult. EtreCheck is a great help that regards.