Eliminate spurious exceptions in destructor

Sometimes when a program exits or aborts you see spurious exception
messages because the destructor is called after python destroys globals.
This change stops those spurious errors.