Instead of sending "#", send the Esc key (#27). The keystroke is registered as activity so it keeps you alive, but seems to be inert in TW.
Granted, that won't help with your problem. The real solution is to determine why the script is crashing and fix it
+EP+