首页 > 解决方案 > 另一个进程错误使用的文件:Python

问题描述

我试图在一些源文件的帮助下更改目标文件的内容。工作完成后,我确保我已经关闭了代码中的所有文件(当然,我确保它也没有在任何编辑器中打开。)

    def write_to_file(self, _source_path, _destination_path):
        f_source = open(_source_path, 'r')
        f_destination = open(_destination_path, 'r')
        f_temp = open(self.temp_path, 'w+')

        while source_line or destination_line:...

        f_temp.close()
        f_destination.close()
        f_source.close()
        shutil.move(self.temp_path, _destination_path)
        return

我收到以下错误:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/rohit.tayal/PycharmProjects/AutoNVMerge/MainActivity.py", line 151, in <module>
    script.write_to_file(source_path, destination_path)
  File "C:/Users/rohit.tayal/PycharmProjects/AutoNVMerge/MainActivity.py", line 62, in write_to_file
    shutil.move(self.temp_path, _destination_path)
  File "C:\Anaconda\envs\AutoNVMerge\lib\shutil.py", line 581, in move
    os.unlink(src)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\auto_nv_merge.xml'

C:\auto_nv_merge.xml是我的临时文件。

标签: pythonpython-3.x

解决方案


工作时

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\auto_nv_merge.xml'

您有 2 个选择,成为英雄并尝试追捕将文件作为人质的进程,或者只是restart您的计算机。

我通常选择后者,restart


推荐阅读