python 线程学习

彩照

一、学习【1】

  

 1 # -*- coding: utf-8 -*-
 2 import time
 3 import thread
 4 
 5 def timer(no, interval):
 6     cnt = 0
 7     while cnt < 10:
 8         print 'Thread (%d), Time is %s \n' % (no, time.ctime())
 9         time.sleep(interval)
10         cnt += 1
11     thread.exit_thread()
12 
13 def test():
14     thread.start_new_thread(timer, (1, 1))
15     thread.start_new_thread(timer, (2, 2))
16 
17 if __name__ == '__main__':
18     test()
19     while 1:
20         pass
--------------------------------------

C:\Python27\python.exe E:/Project/actneed411/furion/static/js/shop/test_captcha.py
Thread (1), Time is Mon Aug 29 10:34:24 2016
Thread (2), Time is Mon Aug 29 10:34:24 2016



Thread (1), Time is Mon Aug 29 10:34:25 2016


Thread (2), Time is Mon Aug 29 10:34:26 2016
Thread (1), Time is Mon Aug 29 10:34:26 2016



Thread (1), Time is Mon Aug 29 10:34:27 2016


Thread (1), Time is Mon Aug 29 10:34:28 2016
Thread (2), Time is Mon Aug 29 10:34:28 2016



Thread (1), Time is Mon Aug 29 10:34:29 2016


Thread (2), Time is Mon Aug 29 10:34:30 2016
Thread (1), Time is Mon Aug 29 10:34:30 2016



Thread (1), Time is Mon Aug 29 10:34:31 2016


Thread (2), Time is Mon Aug 29 10:34:32 2016
Thread (1), Time is Mon Aug 29 10:34:32 2016



Thread (1), Time is Mon Aug 29 10:34:33 2016


Thread (2), Time is Mon Aug 29 10:34:34 2016


Thread (2), Time is Mon Aug 29 10:34:36 2016


Thread (2), Time is Mon Aug 29 10:34:38 2016


Thread (2), Time is Mon Aug 29 10:34:40 2016


Thread (2), Time is Mon Aug 29 10:34:42 2016

 

 

 

 

 

 

 

 

 

 

 

 

----------

  source:【1】Python多线程学习

posted @ 2016-08-29 10:37  半天的半天  阅读(194)  评论(0编辑  收藏  举报