4

I'm trying to write out document using ExcelWriter and encountered the following problem:

when I run my program, it sometimes gives the warning as follows:

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\...\AppData\\Local\\Temp\\tmpk6915sp2'

It is said that the error is from the ExcelWriter .save() method.

I tried to use the .close() method of ExcelWriter, but sometimes the problem still persists. What I mean by sometimes is that if I re-run the program several times, the program just runs like there's no error.

The thing that I don't understand is that why does it /sometimes/ still persists, and how do I solve it?

I encountered several threads with same error but they don't relate to ExcelWriter, I hope anyone could help me. Thanks in advance!

Xantium
  • 11,201
  • 10
  • 62
  • 89
kkharis
  • 47
  • 4
  • Were your paths the same when the error did and did not occur? Perhaps you tried to access a file that was admin protected? – Xantium May 23 '18 at 07:20
  • Is it possible you had the target file open in Excel at the time? That is the commonest cause of this sort of problem. – BoarGules May 23 '18 at 07:34
  • No I did not have the target file open at the time. And also, I think the (temp) file name is different, but the directory is the same. – kkharis May 24 '18 at 06:36
  • Currently what I do is to delete the temp file before I run the program, when the problem occurs – kkharis May 30 '18 at 13:09
  • Could you put the code you are using. It might be useful to try and reproduce it on my computer to help you better. – jalazbe Aug 13 '18 at 09:37

1 Answers1

0

Yes, I have also faced the similar issue with my latest application (developed in windows). In my case, if an exception occurs I have to re-run once again until I get success. so I followed the below snippet to bypass the situation temporarily.

  for count in range(1, 11):
    try:
        print('[+] Running - {}'.format(count))
        # report creation function goes here
        print('[+] Success excel file created.')
        break
    except Exception as error:
        print('[-] Exceptional error - {}'.format(error))
        print('[-] Re-running - {}'.format(count))
        continue
Vijay Anand Pandian
  • 1,027
  • 11
  • 23