You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by hw...@apache.org on 2011/08/10 22:17:55 UTC

svn commit: r1156347 - /subversion/branches/fs-py/subversion/python/svn/fs.py

Author: hwright
Date: Wed Aug 10 20:17:55 2011
New Revision: 1156347

URL: http://svn.apache.org/viewvc?rev=1156347&view=rev
Log:
On the fs-py branch:
Explicitly close files in the Python module, per the Python docs.

* subversion/python/svn/fs.py
  (FS.set_uuid, FS._open_fs): Explicitly close a file, rather than just
    letting it go out of scope.

Modified:
    subversion/branches/fs-py/subversion/python/svn/fs.py

Modified: subversion/branches/fs-py/subversion/python/svn/fs.py
URL: http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/python/svn/fs.py?rev=1156347&r1=1156346&r2=1156347&view=diff
==============================================================================
--- subversion/branches/fs-py/subversion/python/svn/fs.py (original)
+++ subversion/branches/fs-py/subversion/python/svn/fs.py Wed Aug 10 20:17:55 2011
@@ -35,7 +35,10 @@ class FS(object):
             uuid_in = uuid.uuid1()
         self.uuid = uuid_in
 
-        open(self.__path_uuid, 'wb').write(str(self.uuid) + '\n')
+        f = open(self.__path_uuid, 'wb')
+        f.write(str(self.uuid) + '\n')
+        f.close()
+
         # We use the permissions of the 'current' file, because the 'uuid'
         # file does not exist during repository creation.
         shutil.copymode(self.__path_current, self.__path_uuid)
@@ -47,8 +50,9 @@ class FS(object):
 
     def _open_fs(self):
         'Open an existing Subvesion filesystem'
-        self.uuid = uuid.UUID(open(
-                                self.__path_uuid, 'rb').readline().rstrip())
+        f = open(self.__path_uuid, 'rb')
+        self.uuid = uuid.UUID(f.readline().rstrip())
+        f.close()
 
 
     def __setup_paths(self):



Re: svn commit: r1156347 - /subversion/branches/fs-py/subversion/python/svn/fs.py

Posted by Arfrever Frehtes Taifersar Arahesis <ar...@gmail.com>.
2011-08-10 23:34:21 Greg Stein napisał(a):
> On Wed, Aug 10, 2011 at 16:17,  <hw...@apache.org> wrote:
> > Author: hwright
> > Date: Wed Aug 10 20:17:55 2011
> > New Revision: 1156347
> >
> > URL: http://svn.apache.org/viewvc?rev=1156347&view=rev
> > Log:
> > On the fs-py branch:
> > Explicitly close files in the Python module, per the Python docs.
> >
> > * subversion/python/svn/fs.py
> >  (FS.set_uuid, FS._open_fs): Explicitly close a file, rather than just
> >    letting it go out of scope.
> 
> Hunh? Which docs? This only makes sense if you're running in alternate
> Python environments like Jython. CPython closes the file when the
> refcount his zero.

CPython >=3.2 detects files (and sockets) not closed explicitly or via __exit__() and can print ResourceWarnings.

$ python2.7 -Wd -c 'open("/dev/null")'
$ python3.1 -Wd -c 'open("/dev/null")'
$ python3.2 -Wd -c 'open("/dev/null")'
-c:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>

-- 
Arfrever Frehtes Taifersar Arahesis

Re: svn commit: r1156347 - /subversion/branches/fs-py/subversion/python/svn/fs.py

Posted by Greg Stein <gs...@gmail.com>.
On Wed, Aug 10, 2011 at 16:17,  <hw...@apache.org> wrote:
> Author: hwright
> Date: Wed Aug 10 20:17:55 2011
> New Revision: 1156347
>
> URL: http://svn.apache.org/viewvc?rev=1156347&view=rev
> Log:
> On the fs-py branch:
> Explicitly close files in the Python module, per the Python docs.
>
> * subversion/python/svn/fs.py
>  (FS.set_uuid, FS._open_fs): Explicitly close a file, rather than just
>    letting it go out of scope.

Hunh? Which docs? This only makes sense if you're running in alternate
Python environments like Jython. CPython closes the file when the
refcount his zero.

I'm failing to see the reasoning here...

Cheers,
-g