流程
- 导入threading模块
- 创建子线程
- 启动子线程
demo
import threading
import time
def sing():
for i in range(3):
print("sing...")
time.sleep(0.2)
pass
def dance():
for i in range(3):
print("dance...")
time.sleep(0.2)
pass
if __name__ == '__main__':
sing_thread = threading.Thread(target=sing)
sing_thread.start()
dance_thread = threading.Thread(target=dance)
dance_thread.start()