标题: [技术讨论] Python多进程浏览文件夹 [打印本页]
作者: Gin_Q 时间: 2020-6-3 15:19 标题: Python多进程浏览文件夹
- #!/usr/bin/env python3
- #coding:utf-8
-
- import multiprocessing as multi
- import os
-
- class thr(multi.Process):
- def __init__(self,folder):
- multi.Process.__init__(self)
- self.folder = folder
-
- def run(self):
- for root,dirs,files in os.walk(self.folder.get()):
- print('父目录:',root)
- print('文件夹:',dirs)
- for f in files:
- print(f)
- self.folder.task_done()
-
- def Process_pool(q):
- th = thr(q)
- th.daemon = True
- th.start()
-
- if __name__ == '__main__':
- q = multi.JoinableQueue()#队列
-
- #进程池
- Process_pool(q)
- Process_pool(q)
-
- folder = [r'D:\GIN\c',r'D:\GIN\py']
- for i in range(len(folder)):
- q.put(folder[i])
-
- q.join()#等待队列清空
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |