1 import _thread
 2 import time
 3 def fun1(thread_name,delay):
 4     print('开始运行fun1,线程的名:',thread_name)
 5     time. sleep(delay)
 6     print('运行fun1结束')
 7 
 8 def fun2(thread_name,delay):
 9     print('开始运行fun2,线程的名:',thread_name)
10     time.sleep(delay)
11     print('运行fun2结束')
12 if __name__ == '__main__':
13     print('开始运行')
14     #创建线程
15     _thread.start_new_thread(fun1,('thread-1',3))
16     time.sleep(2)
17     _thread.start_new_thread(fun2,('thread-2',3))
18     time.sleep(7)
1 开始运行
2 开始运行fun1,线程的名: thread-1
3 开始运行fun2,线程的名: thread-2
4 运行fun1结束
5 运行fun2结束

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2020-02-03
猜你喜欢
  • 2021-09-14
  • 2019-06-12
  • 2021-05-28
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2022-02-16
相关资源
相似解决方案