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

前端 未结 4 530
南笙
南笙 2020-11-27 07:39

My code is for a script that looks at a folder and deletes images that are under a resolution of 1920x1080. The problem I am having is that when my code runs;



        
4条回答
  •  萌比男神i
    2020-11-27 08:09

    I also had the issue, in windows [WinError 32]

    Solved by changing:

    try:
        f = urllib.request.urlopen(url)
        _, fname = tempfile.mkstemp()
        with open(fname, 'wb') as ff:
            ff.write(f.read())
        img = imread(fname)
        os.remove(fname)
        return img
    

    into:

    try:
        f = urllib.request.urlopen(url)
        fd, fname = tempfile.mkstemp()
        with open(fname, 'wb') as ff:
            ff.write(f.read())
        img = imread(fname)
        os.close(fd)
        os.remove(fname)
        return img
    

    As found here: https://no.coredump.biz/questions/45042466/permissionerror-winerror-32-when-trying-to-delete-a-temporary-image

提交回复
热议问题