我使用python shuitl.copy2方法从共享文件夹复制一些文件,复制成功后将启动一个需要访问这些复制文件的进程。的问题是有时有一个文件不能被新进程访问,错误32被报告。我的脚本正在循环运行,但这个问题并不是每次都会发生。有人知道问题出在哪里吗?
更新一些简单的代码。特定请求触发MyThread运行,在复制结束后,另一个可执行的应用程序将使用这些文件,应用程序报告Error32。
class MyThread(threading.Thread):
def __init__(self, fileList, destFolder):
threading.Thread.__init__(self)
def run(self):
for fileItem in self.fileList:
if self.stop:
break
try:
self.__copyFile(fileItem, localDestFolder)
self.successList.append(fileItem)
except Exception, e:
self.errorList.append((fileItem, str(e)))
@staticmethod
def __copyFile(source, destination):
print 'Use shutil to copy file %s' % source
shutil.copy2(source, destination)
print 'Copy end'发布于 2016-08-24 08:08:45
文件指针可能没有正确关闭。
也许在复制和进程开始之间添加一点time.sleep()。
https://stackoverflow.com/questions/39117734
复制相似问题