推荐学习书目
› 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
oldbird
V2EX  ›  Python

shutil 复制会在本地做缓存?

  •  
  •   oldbird · Jun 26, 2019 via Android · 2116 views
    This topic created in 2651 days ago, the information mentioned may be changed or developed.
    在本机上写了个 py 文件用 shutil 实现文件拷贝,当源文件和目标地址都在挂载的服务器共享盘上时,发现速度很慢很慢,试了一下耗时约是用 dos copy 命令的 4 倍,是否因为 shutil 需要先读取数据到本机,然后再写入目标地址的缘故?
    2 replies  •  2019-06-28 09:06:06 +08:00
    ysc3839
        1
    ysc3839  
       Jun 27, 2019 via Android
    是的。
    1462326016
        2
    1462326016  
       Jun 28, 2019
    def copyfileobj(fsrc, fdst, length=16*1024):
    """copy data from file-like object fsrc to file-like object fdst"""
    while 1:
    buf = fsrc.read(length)
    if not buf:
    break
    fdst.write(buf)

    看源代码的话目测是的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2551 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 15:34 · PVG 23:34 · LAX 08:34 · JFK 11:34
    ♥ Do have faith in what you're doing.