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
oldbird
V2EX  ›  Python

shutil 复制会在本地做缓存?

  •  
  •   oldbird · 2019-06-26 19:06:03 +08:00 via Android · 1389 次点击
    这是一个创建于 1765 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在本机上写了个 py 文件用 shutil 实现文件拷贝,当源文件和目标地址都在挂载的服务器共享盘上时,发现速度很慢很慢,试了一下耗时约是用 dos copy 命令的 4 倍,是否因为 shutil 需要先读取数据到本机,然后再写入目标地址的缘故?
    2 条回复    2019-06-28 09:06:06 +08:00
    ysc3839
        1
    ysc3839  
       2019-06-27 02:22:02 +08:00 via Android
    是的。
    1462326016
        2
    1462326016  
       2019-06-28 09:06:06 +08:00
    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)

    看源代码的话目测是的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3238 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 14:02 · PVG 22:02 · LAX 07:02 · JFK 10:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.