CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day13/singlethread1.py
Views: 729
1
"""
2
不使用多线程的情况 - 模拟多个下载任务
3
4
Version: 0.1
5
Author: 骆昊
6
Date: 2018-03-20
7
"""
8
9
from random import randint
10
from time import time, sleep
11
12
13
def download_task(filename):
14
print('开始下载%s...' % filename)
15
time_to_download = randint(5, 10)
16
sleep(time_to_download)
17
print('下载完成! 耗费了%d秒' % time_to_download)
18
19
20
def main():
21
start = time()
22
download_task('Python从入门到住院.pdf')
23
download_task('Peking Hot.avi')
24
end = time()
25
print('总共耗费了%.2f秒.' % (end - start))
26
27
28
if __name__ == '__main__':
29
main()
30
31