[python-win32] lingering open filehandle?

Mark Hammond skippy.hammond at gmail.com
Thu Feb 9 02:37:19 CET 2012


On 9/02/2012 12:17 PM, Andrew Hammond wrote:
> We're using pycurl to download a file. The file is written to disk in
> the context of a with statement. Once the file is written, we exit the
> context and then do an os.rename() to move the downloaded file to it's
> final destination. Immediately before doing the rename, I confirm that
> the filehandle is closed. However, it appears that there is some lag
> between when it says the filehandle is close and when it actually gets
> closed because I often get a "[Error 32] The process cannot access the
> file because it is being used by another process" exception raised on
> the rename operation. Is this a known issue? Running python 2.6 on win32.

A virus scanner or indexer can cause this problem - it sees the new file 
then opens it to do its thing.  If that sounds like the problem you 
could either disable whatever tool is causing the problem, or just have 
a loop which tries once per second for a few seconds...

Mark


More information about the python-win32 mailing list