> Can't you check whether threading.current_thread().name == 'MainThread' instead?

That's a good suggestion.