0

This is my error:

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

I call the function below from a worker thread, when its done its long running process. It stops the thread and then gives it 10 secs before showing a dialog box and renaming the file. "Unlocker" shows that the file is only open in Python.exe.

 def allDone(self, event):
    myClass.worker.stop()
    for i in range(0,10):
        time.sleep(1)
        print(i)
    dlg = wx.MessageBox("All done!", "Ask Alfred", wx.OK | wx.ICON_INFORMATION)
    os.rename(self.tempf, self.tempf+"123.xls")
    self.Destroy()

The file gets opened in the code via xlrd methods below in the worker thread:

rbook=xlrd.open_workbook(self.file)
sheet = rbook.sheet_by_index(0)
wbook = copy(rbook)
ohbrobig
  • 939
  • 2
  • 13
  • 34

1 Answers1

0

The file needs to be closed in all processes even "Python.exe" before you can move it.

This question seems like you need to let this xlrd object go out of scope so that it will be closed on its own before you try to move and rename the file.

If you have references to that file in your threads, then you should try setting the variable to None so that the references to the file object are removed when processing is complete. Hopefully that will fix your problem

Community
  • 1
  • 1
Dan
  • 1,096
  • 9
  • 13