threads.py 688 B

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. '''
  3. 多线程下载多文件;多线程分段下载单文件.
  4. @Auther :liuyuqi.gov@msn.cn
  5. @date :2019/4/8
  6. '''
  7. __author__ = "liuyuqi"
  8. from threading import Lock
  9. from threading import Thread
  10. threadLock = Lock()
  11. threads = []
  12. class MyThread(Thread):
  13. def __init__(self, name, func, *args, lock=False):
  14. Thread.__init__(self)
  15. self.name = name
  16. self.func = func
  17. self.args = args
  18. self.lock = lock
  19. def run(self):
  20. print("开启: " + self.name)
  21. if self.lock:
  22. threadLock.acquire()
  23. self.func(*self.args)
  24. threadLock.release()
  25. else:
  26. self.func(*self.args)