I'm assuming the programmers original intention was for that block of code to be executed when Vizard exits. If this is the case, then it would be better to execute the code during viz.EXIT_EVENT, instead of when the escape key is pressed. Try the following instead:
Code:
def onExit():
print 'This will appear before Vizard exits'
viz.callback(viz.EXIT_EVENT,onExit)