流程

  • 导入threading模块
  • 创建子线程
  • 启动子线程

demo

  1. import threading
  2. import time
  3. def sing():
  4. for i in range(3):
  5. print("sing...")
  6. time.sleep(0.2)
  7. pass
  8. def dance():
  9. for i in range(3):
  10. print("dance...")
  11. time.sleep(0.2)
  12. pass
  13. if __name__ == '__main__':
  14. sing_thread = threading.Thread(target=sing)
  15. sing_thread.start()
  16. dance_thread = threading.Thread(target=dance)
  17. dance_thread.start()