shutil.move, permission denied, why ?

Stéphane Ninin stefnin at alussinan.org
Thu Apr 8 06:05:28 EDT 2004


Also sprach Colin Brown :

> 
> Some time ago I had a "permission denied" problem on Windows that I
> finally tracked down to os.system duplicating open handles at the
> creation instance! The method I used to locate the problem area was by
> having python fire off an instance of handle.exe (freely available from
> www.sysinternals.com) when the permission error occurred to see what
> else had the file open. 
> 

  Thanks for the idea. It helps.

On this part of the code:
(see <Xns94C49F78550F2stefninalussinanorg at 212.27.42.71> for full test 
script) 

    def read(self,filename):

        from _xmlplus.sax.sax2exts import XMLValParserFactory
        parser = XMLValParserFactory.make_parser()

        dh = DefaultHandler()
        
        parser.setContentHandler(dh)
        parser.setErrorHandler(dh)
        
        f = file(filename,'r')

        
        print 'TestReader B'
        system('handle.exe xml')
        r=raw_input('Press\n')

        
        try:
            parser.parse(f)
        finally:
            print 'CLOSE FILE'
            parser.close()
            parser.reset()
            f.close()
            print 'TestReader C'
            system('handle.exe xml')
            r=raw_input('Press\n')
            print f.closed
            
            
        return 1


I have the following output for a "bad file"
(parser throws exception during parsing):
 

TestReader B

Handle v2.2
Copyright (C) 1997-2004 Mark Russinovich
Sysinternals - www.sysinternals.com

python.exe         pid: 1776   path to test3.xml
CMD.EXE            pid: 1304   path to test3.xml
handle.exe         pid: 1072   path to test3.xml
Press

CLOSE FILE
B1

Handle v2.2
Copyright (C) 1997-2004 Mark Russinovich
Sysinternals - www.sysinternals.com

python.exe         pid: 1776   path to test3.xml
CMD.EXE            pid: 1020   path to test3.xml
handle.exe         pid: 1724   path to test3.xml
Press


... while, for a file which is correctly parsed I have this output:

TestReader B

Handle v2.2
Copyright (C) 1997-2004 Mark Russinovich
Sysinternals - www.sysinternals.com

python.exe         pid: 1324   path to test3.xml
CMD.EXE            pid: 1020   path to test3.xml
handle.exe         pid: 1776   path to test3.xml
Press

CLOSE FILE
TestReader C

Handle v2.2
Copyright (C) 1997-2004 Mark Russinovich
Sysinternals - www.sysinternals.com

No matching handles found.
Press

  ~~~

I am not sure I am interpreting this correctly... 
Even if file is closed (as say f.closed),
handles are still there ?

And if problem comes from the parser (PyXML), I guess I will somehow 
workaround the problem, as I dont want to dig into PyXML code. :) 
(Unless you have some other idea.)
Well, I will also test this week-end if problem also happens on Linux.
(as this code is supposed to run only on Linux,
I will just skip this problem if it works fine on linux)

Thanks for your suggestion.


  Regards,

-- 
Stephane Ninin

   






More information about the Python-list mailing list