gpt4 book ai didi

python - copy2权限错误: [WinError 32] The process cannot access the file because it is being used by another process:

转载 作者:太空宇宙 更新时间:2023-11-04 02:58:19 25 4
gpt4 key购买 nike

我正在复制一个文件到临时目录

def uploadAvatar(self, schid, img):
try:
img = path.abspath(img)
filename = self.generateAvatarFileName(schid)
temp_dir = tempfile.gettempdir()
self.tmp = path.join(temp_dir, filename)
copy2(img, self.tmp)
#imgname = path.basename(self.tmp)
imgdir = path.dirname(self.tmp)+path.sep
self.retcode = ts3lib.createReturnCode()
(error, ftid) = ts3lib.sendFile(schid, 0, "", "/avatar/"+filename, True, False, imgdir, self.retcode);
except:
try: from traceback import format_exc;ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "PyTSon Script", 0)
except:
try: from traceback import format_exc;print(format_exc())
except: print("Unknown Error")

上传后想删除

def onServerErrorEvent(self, schid, errorMessage, error, returnCode, extraMessage):
if self.retcode == returnCode: self.setAvatar(schid, self.tmp);remove(self.tmp)

但我总是得到

Error calling method of plugin Dynamic Avatar Changer: Traceback (most recent call last):
File "C:/Users/blusc/AppData/Roaming/TS3Client/plugins/pyTSon/scripts\ts3plugin.py", line 259, in callMethod
ret.append(meth(*args))
File "C:/Users/blusc/AppData/Roaming/TS3Client/plugins/pyTSon/scripts\dynamicAvatar\__init__.py", line 114, in onServerErrorEvent
if self.retcode == returnCode: self.setAvatar(schid, self.tmp);remove(self.tmp)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\blusc\\AppData\\Local\\Temp\\avatar_ZFV2RGU5MjNmb0NyN3hsN1NnU3BGQzdsTFZZPQ'

如何做到这一点?请帮忙!

最佳答案

听起来您需要关闭文件或停止进程这是一个链接,我发现我能够解决您的问题。 File handling in Python - PermissionError: [WinError 32] The process cannot access the file because it is being used by another process .

关于python - copy2权限错误: [WinError 32] The process cannot access the file because it is being used by another process:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41710531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com