| 14 | |
| 15 | |
| 16 | class DownloadTask(threading.Thread): |
| 17 | |
| 18 | def __init__(self, filename): |
| 19 | super().__init__() |
| 20 | self._filename = filename |
| 21 | |
| 22 | def run(self): |
| 23 | print('开始下载%s...' % self._filename) |
| 24 | time_to_download = randint(5, 10) |
| 25 | print('剩余时间%d秒.' % time_to_download) |
| 26 | sleep(time_to_download) |
| 27 | print('%s下载完成!' % self._filename) |
| 28 | |
| 29 | |
| 30 | def main(): |