找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 11512|回复: 0

[技术讨论] Python多进程浏览文件夹

[复制链接]
发表于 2020-6-3 15:19:03 | 显示全部楼层 |阅读模式
  1. #!/usr/bin/env python3
  2. #coding:utf-8

  3. import multiprocessing as multi
  4. import os

  5. class thr(multi.Process):
  6.     def __init__(self,folder):
  7.         multi.Process.__init__(self)
  8.         self.folder = folder
  9.    
  10.     def run(self):
  11.         for root,dirs,files in os.walk(self.folder.get()):
  12.             print('父目录:',root)
  13.             print('文件夹:',dirs)
  14.             for f in files:
  15.                 print(f)
  16.         self.folder.task_done()

  17. def Process_pool(q):
  18.     th = thr(q)
  19.     th.daemon = True
  20.     th.start()   

  21. if __name__ == '__main__':
  22.     q = multi.JoinableQueue()#队列
  23.    
  24.     #进程池
  25.     Process_pool(q)
  26.     Process_pool(q)
  27.    
  28.     folder = [r'D:\GIN\c',r'D:\GIN\py']
  29.     for i in range(len(folder)):
  30.         q.put(folder[i])
  31.    
  32.     q.join()#等待队列清空
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 06:00 , Processed in 0.016324 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表