def test_is_main_thread(): if sys.version_info[0] >= 3: # NB: the test itself doesn't necessarily run in main thread... is_main = (threading.current_thread() == threading.main_thread()) assert util.is_main_thread() == is_main results = [] def worker(): results.append(util.is_main_thread()) thread = threading.Thread(target=worker) thread.start() thread.join() assert results == [False]
def worker(): results.append(util.is_main_thread())