Fix issue in GaudiPython atexit handler with Python 3
the change in !875 (diffs) is actually introducing a regression when using Python 3 instead of Python 2.
This change fixes the problem and resolves lhcb/LHCb!2214 (comment 3642987)
I also added a minor fix for a special case.
Edited by Marco Clemencic