_thread实现线程(传递参数)

 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结束

 

posted @ 2020-04-11 21:32  小他_W  阅读(3497)  评论(0编辑  收藏  举报