@josete2k If Kodi crashes, with default settings, and doing simple things like that, your problem is likely a hardware one. Make sure you have a good SD card and a good power supply, preferebly a one piece one, whitout a separate usb cable.
Making a python script to kill/restart Kodi isn't going to do any better.