def test_name(): name_list = [] NameManager.current = NameManager() NameManager.current.get(None, "main_thread") name_list.append(NameManager.current) def f(): NameManager.current = NameManager() NameManager.current.get(None, "spawned_thread") name_list.append(NameManager.current) thread = threading.Thread(target=f) thread.start() thread.join() assert "main_thread" in name_list[ 0]._counter, "cannot find the string `main thread` in name_list[0]._counter" assert "spawned_thread" in name_list[ 1]._counter, "cannot find the string `spawned thread` in name_list[1]._counter" event = threading.Event() status = [False] def g(): with NameManager(): if "main_thread" not in NameManager.current._counter: status[0] = True thread = threading.Thread(target=g) thread.start() NameManager.current = NameManager() NameManager.current.get(None, "main_thread") event.set() thread.join() event.clear() assert status[0], "Spawned thread isn't using thread local NameManager"
def g(): with NameManager(): if "main_thread" not in NameManager.current._counter: status[0] = True
def f(): NameManager.current = NameManager() NameManager.current.get(None, "spawned_thread") name_list.append(NameManager.current)