_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結束

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM