[pypy-svn] pypy default: Change the test to keep track of all files opened, and close

arigo commits-noreply at bitbucket.org
Tue Feb 15 15:40:19 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r41953:468752b873fc
Date: 2011-02-15 15:33 +0100
http://bitbucket.org/pypy/pypy/changeset/468752b873fc/

Log:	Change the test to keep track of all files opened, and close the
	older ones, with a buffer of 50. This avoids getting an infinite
	number of open files, hopefully.

diff --git a/lib-python/modified-2.7.0/test/test_file2k.py b/lib-python/modified-2.7.0/test/test_file2k.py
--- a/lib-python/modified-2.7.0/test/test_file2k.py
+++ b/lib-python/modified-2.7.0/test/test_file2k.py
@@ -450,6 +450,9 @@
         self.close_count = 0
         self.close_success_count = 0
         self.use_buffering = False
+        # to prevent running out of file descriptors on PyPy,
+        # we only keep the 50 most recent files open
+        self.all_files = [None] * 50
 
     def tearDown(self):
         if self.f:
@@ -465,9 +468,14 @@
 
     def _create_file(self):
         if self.use_buffering:
-            self.f = open(self.filename, "w+", buffering=1024*16)
+            f = open(self.filename, "w+", buffering=1024*16)
         else:
-            self.f = open(self.filename, "w+")
+            f = open(self.filename, "w+")
+        self.f = f
+        self.all_files.append(f)
+        oldf = self.all_files.pop(0)
+        if oldf is not None:
+            oldf.close()
 
     def _close_file(self):
         with self._count_lock:


More information about the Pypy-commit mailing list