In your wscript
module, you can use the Python standard library's atexit to register callables that you want to be called when the process exit. For example:
import atexit
import time
class MayBeep(object):
def __init__(self, deadline=10.0):
self.deadline = time.time() + deadline
def __call__(self):
if time.time() > self.deadline():
print '\7'
atexit.register(MayBeep())
... rest of your wscript module ...
Of course you may use something better than print '\7'
for beeping purposes (all the way to full-fledged multimedia extravaganzas, depending on what other Python extensions you import and use), but this code answers the Q's title -- "add code that's always executed on exit".