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