Maybe try using the idiom:
if __name__=="__main__":
main()
Instead of calling main since the way it’s written now it will always run your code as soon as your module is imported. If the system expects a function named main and calls it, remove your call to main at the end.
Pretty sus :P
I would start by removing the graphics card if you have integrated graphics available (or disable the PCI port in your bios)
This reminds me of the kinds of issues I would get when setting up overclocking and getting just past the limit of stable operation. If you have overclocking set up definitely try disabling it.
If removing the GPU does nothing don’t forget to check removing each ram stick separately, or make sure your bios runs a full memory check.