python import threading def thread_function(name): print("Thread {} started".format(name)) print("Thread {} finished".format(name)) thread_1 = threading.Thread(target=thread_function, args=(1,)) thread_2 = threading.Thread(target=thread_function, args=(2,)) thread_1.start() thread_2.start() thread_1.join() thread_2.join() print("All threads finished") python import concurrent.futures def thread_function(name): print("Thread {} started".format(name)) print("Thread {} finished".format(name)) with concurrent.futures.ThreadPoolExecutor() as executor: future_1 = executor.submit(thread_function, 1) future_2 = executor.submit(thread_function, 2) concurrent.futures.wait([future_1, future_2]) print("All threads finished")


上一篇:
下一篇:
切换中文