单线程:按顺序执行任务
代码如下:
#coding=utf-8
#单线程:按顺序执行任务
from time import sleep,ctime
#创建音乐任务
def music(func):
for i in range(2):
print('I was listening to %s! %s'%(func,ctime()))
sleep(2)
#创建看电影任务
def movie(func):
for i in range(2):
print('I was at the %s! %s'%(func,ctime()))
sleep(3)
if __name__ == "__main__":
music("Just one last dance")
movie(u"都挺好")
print("All end:",ctime())
运行结果为:
I was listening to Just one last dance! Mon Feb 1 22:22:18 2021
I was listening to Just one last dance! Mon Feb 1 22:22:20 2021
I was at the 都挺好! Mon Feb 1 22:22:22 2021
I was at the 都挺好! Mon Feb 1 22:22:25 2021
All end: Mon Feb 1 22:22:28 2021
网友评论