pip install threading pip install multiprocessing pip install concurrent.futures python import threading def print_hello(): for _ in range(10): print("Hello") def print_world(): for _ in range(10): print("World") thread1 = threading.Thread(target=print_hello) thread2 = threading.Thread(target=print_world) thread1.start() thread2.start() thread1.join() thread2.join() print("Done") python import threading def print_hello(): for _ in range(10): print("Hello") def print_world(): for _ in range(10): print("World") thread1 = threading.Thread(target=print_hello, name="HelloThread") thread2 = threading.Thread(target=print_world, name="WorldThread") thread1.start() thread2.start() thread1.join() thread2.join() print("Done")


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