python 线程学习

彩照

一、学习【1】

  

 # -*- coding: utf-8 -*-
import time
import thread def timer(no, interval):
cnt = 0
while cnt < 10:
print 'Thread (%d), Time is %s \n' % (no, time.ctime())
time.sleep(interval)
cnt += 1
thread.exit_thread() def test():
thread.start_new_thread(timer, (1, 1))
thread.start_new_thread(timer, (2, 2)) if __name__ == '__main__':
test()
while 1:
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多线程学习

上一篇:Python自动发送邮件-smtplib和email库


下一篇:[MySQL]支持 emoji(字符集问题)