In which case should I then add:
 
try
 ...
finally:
 file.close()
 
In all places a file is opened?
Before I suggest it as a bug fix?
 
Cheers,
 
Gareth

 

From: Sébastien Boisgérault [mailto:Sebastien.Boisgerault@mines-paristech.fr]
Sent: 29 September 2009 17:57
To: DOUTCH GARETH-GDO003
Cc: jython-users@lists.sourceforge.net
Subject: Re: [Jython-users] File lock issue

Gareth,

Gareth,

Could you also file a bug and suggest the bug fix to CPython ?
So far Jython used the CPython ElementTree.py file, it would be nice to continue this way.

Cheers,

SB


DOUTCH GARETH-GDO003 a écrit :
OK I've answered my own question. Modifying Lib\xml\etree\ElementTree.py
like so seems to cure the issue:

@line 577:

    def parse(self, source, parser=None):
        try:
            if not hasattr(source, "read"):
                source = open(source, "rb")
            if not parser:
                parser = XMLTreeBuilder()
            while 1:
                data = source.read(32768)
                if not data:
                    break
                parser.feed(data)
            self._root = parser.close()
            return self._root
        finally:
            if hasattr(source, "read"):
                source.close()



Thanks for the pointers!

Cheers,

Gareth 

-----Original Message-----
From: DOUTCH GARETH-GDO003 
Sent: 29 September 2009 09:33
To: jython-users@lists.sourceforge.net
Subject: Re: [Jython-users] File lock issue

Hi there,

I've logged a ticket.
http://bugs.jython.org/issue1479

Is there any kind of workaround? Do I need to patch the elementtree
module? 

This issue is blocking my migration to 2.5 from 2.2.

Cheers,

Gareth


-----Original Message-----
From: Philip Jenvey [mailto:pjenvey@underboss.org]
Sent: 28 September 2009 22:32
To: Tobias Ivarsson
Cc: DOUTCH GARETH-GDO003; jython-users@lists.sourceforge.net
Subject: Re: [Jython-users] File lock issue


On Sep 28, 2009, at 1:29 PM, Tobias Ivarsson wrote:

  
Ok, I've discussed this with my colleague, and the only solution is to
    

  
not use memory mapped IO on Windows. Performance of regular IO buffers
    

  
on Windows is (according to his benchmarks) even slightly better than 
the memory mapped ones on Windows (oddly enough).

The next step on this issue is to look at the IO code in Jython (this 
is not a part of Jython I've been involved with that much) to verify 
that this actually is the problem, and then modify it so that Jython 
doesn't use memory mapped IO on Windows.
    

We don't do use mmapped IO. I think this is jt ElementTree.parse
assuming CPython ref counting and not closing its file handles, combined
with the fact that Windows disallows removal of a file when it's in use.

Gareth, could you please log a ticket for this on the bug tracker?

  
I don't have the time to look deeper into this at the moment, so if 
someone else on the dev team has some time over to take a look at 
this, that would be great.

Cheers,
Tobias

On Mon, Sep 28, 2009 at 8:16 PM, Tobias Ivarsson <thobes@gmail.com>
wrote:
I know there is an issue with file locks being retained after files 
are closed on Windows:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4715154

And I think the features that trigger this bug are used in Jython.  
The symptoms described here are exactly the ones I've seen with this 
issue before.

I know a guy with excellent knowledge in this area, I'll get back when
    

  
I've consulted him on how this can be worked around on the insides of 
Jython. Until then your best bet is to use a better operating system.

cheers,
Tobias

On Mon, Sep 28, 2009 at 4:53 PM, DOUTCH GARETH-GDO003 
<Gareth.Doutch@motorola.com
    
wrote:
      
Hi there,

I have a problem with an xml file locking after read and/or write.

I have a short sample code with unit test attached. Below are the 
outputs from Jython and CPython (v 2.5.4). Is this a bug?
Can anybody offer an alternative workaround?

I am using Jython 2.5.1 on Windows XP and java version "1.6.0_16".

Cheers,

Gareth


    
jython lock.py
      
E
======================================================================
ERROR: runTest (__main__.TestDelete)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "W:\testTeam\SIT\JySit\sit\scripts\lock.py", line 73, in 
tearDown
    os.remove(self.fileName)
  File "C:\jython2.5.1\Lib\os.py", line 342, in remove
    raise OSError(0, "couldn't delete file", path)
OSError: [Errno 0] couldn't delete file: 'C:\\testdir\\test.xml'

----------------------------------------------------------------------
Ran 1 test in 0.454s

FAILED (errors=1)


    
python lock.py
      
.
----------------------------------------------------------------------
Ran 1 test in 0.015s

OK

    

--
Philip Jenvey


------------------------------------------------------------------------
------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and
stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register
now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users