- #!/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()#等待队列清空
复制代码
|