import _thread import time barrier = 0 def method(): import threading # Will make threading the wrong thread. global barrier barrier = 1 _thread.start_new_thread(method, ()) while barrier != 1: time.sleep(.1) import threading print(threading.main_thread()) print(threading.current_thread()) # CPython will give an exception if we exit here without waiting # for what it thinks is the main thread to exit first . threading.main_thread().join()