Can you post a working script? I can't actually run the code you posted since it is not a fully working script. Either way, you might want to look at the documentation for
viz.ACTION_END_EVENT. It shows a simple example on how to correctly handle the callback.