I would recommend to check the system logs to see what’s causing the machine to restart.
A failing Python script should just raise an error, but shouldn’t take down the whole workstation so I guess your current system might encounter some critical issues.