import sys
from signal import *

__author__ = 'paoolo'

__trap_signals = (SIGINT, SIGTERM)
__funcs = []


def __shutdown_func(*args, **kwargs):
    sys.stderr.write('trap signal\n')
    for func in __funcs:
        func()


for sig in __trap_signals:
    signal(sig, __shutdown_func)


def add_shutdown_hook(func):
    __funcs.append(func)
@@ -99,16 +99,48 @@
  = %5B%5D%0A%0A%0A
+# noinspection PyBroadException%0A
 def __sh
@@ -244,14 +244,64 @@
     
-func()
+try:%0A            func()%0A        except:%0A            pass
 %0A%0A%0Af

Update runtime shutdown hook mechanism