@linux1s1s
2017-08-09T18:35:49.000000Z
字数 1278
阅读 1410
Python
2017-08
这里简要记录
Python核心编程
读书笔记 整段代码 可以直接运行
# -*- coding:gb18030 -*-
# 主线程
from time import sleep, ctime
def loop0():
print 'start loop 0 at: ', ctime()
sleep(4)
print 'stop loop 0 at: ', ctime()
def loop1():
print 'start loop 1 at: ', ctime()
sleep(2)
print 'stop loop 1 at: ', ctime()
def main():
print 'Starting at: ', ctime()
loop0()
loop1()
print 'Stop at: ', ctime()
if __name__ == '__main__':
main()
C:\Python27\python.exe H:/workspace/python-hw/hw-3.py
Starting at: Wed Aug 09 18:35:47 2017
start loop 0 at: Wed Aug 09 18:35:47 2017
stop loop 0 at: Wed Aug 09 18:35:51 2017
start loop 1 at: Wed Aug 09 18:35:51 2017
stop loop 1 at: Wed Aug 09 18:35:53 2017
Stop at: Wed Aug 09 18:35:53 2017
Process finished with exit code 0
# -*- coding:gb18030 -*-
import thread
from time import sleep, ctime
def loop0():
print 'Starting loop 0 at: ', ctime()
sleep(4)
print 'Stop loop 0 at: ', ctime()
def loop1():
print 'Starting loop 1 at: ', ctime()
sleep(2)
print 'Stop loop 1 at: ', ctime()
def main():
print 'Starting at: ', ctime()
thread.start_new_thread(loop0, ())
thread.start_new_thread(loop1, ())
sleep(6)
print 'Stop at: ', ctime()
if __name__ == '__main__':
main()
C:\Python27\python.exe H:/workspace/python-hw/hw-4.py
Starting at: Wed Aug 09 18:36:09 2017
Starting loop 0 at: Wed Aug 09 18:36:09 2017
Starting loop 1 at: Wed Aug 09 18:36:09 2017
Stop loop 1 at: Wed Aug 09 18:36:11 2017
Stop loop 0 at: Wed Aug 09 18:36:13 2017
Stop at: Wed Aug 09 18:36:15 2017