我有以下 Python 函数,我在 Windows 7 上运行:
def update():
temp_dir = tempfile.mkdtemp()
git.Git().clone('my_repo', temp_dir)
try:
repo = git.Repo(temp_dir)
repo.index.add('*')
repo.index.commit('Empty commit')
finally:
from git.util import rmtree
rmtree(temp_dir)
不幸的是,在 rmtree 线上,我得到:
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\myaccount\\appdata\\local\\temp\\tmpdega8h\\.git\\objects\\pack\\pack-0ea07d13498ab92388dc33fbabaadf37511623c1.idx'
我应该怎么做才能删除 Windows 中的临时目录?