V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Yycreater
V2EX  ›  Python

进程池问题~~~

  •  
  •   Yycreater ·
    Yycreater · 2018-04-26 21:17:44 +08:00 · 1246 次点击
    这是一个创建于 2162 天前的主题,其中的信息可能已经有所发展或是发生改变。
    #使用进程池将一个目录复制到其他目录下
    def myCopy(file):
    # 文件与旧路径拼接为绝对路径
    newSrcpath = os.path.join(src, file)
    # 文件与旧路径拼接为绝对路径
    newDispath = os.path.join(dst, file)

    open(newDispath, 'wb').write(open(newSrcpath, 'rb').read())
    print('文件写入完成')

    src = r'C:\Users\様\Desktop\md 集合'
    dst = r'D:\Class 资料\多线程测试'

    if __name__ == '__main__':
    start = time.time()
    #读取文件以列表形式返回
    fileList = os.listdir(src)
    #创建线程池
    pp = Pool()
    #开启线程池
    pp.map(myCopy,fileList)
    pp.close()
    pp.join()
    end = time.time()
    print('用时', end - start, '秒')
    print('OVER')


    我想用进程池实现一个将一个目录下的所有文件复制到另一个目录的文件下,还是用多进程改的,结果报了许多语法错误~求 dalao 帮忙看一下~~~给点意见
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4986 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:47 · PVG 17:47 · LAX 02:47 · JFK 05:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.