Add more error handling

Change-Id: I353b9712eb9f5055eda9c20921c2554bd6427ee1
Fix shutdown problem

Make the python interpreter exit when any thread encounters an error.

Change-Id: I583f4afc67564390e3b2c74b85d82e77d8105312
Merge commit 'ec24b5aee4af7f5ca206c1530e10ecb64bc98960'