Bluscream
Bluscream

Reputation: 253

copy2 PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:

I'm copying a file to the temp dir

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")

and want to delete it after I uploaded it

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

But I always get

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'

How can accomplish this? Please help!

Upvotes: 2

Views: 11516

Answers (1)

Blake
Blake

Reputation: 21

Sounds like you need to close the file or stop the process heres a link I found that my be able to solve your problem. File handling in Python - PermissionError: [WinError 32] The process cannot access the file because it is being used by another process.

Upvotes: 2

Related Questions