diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-18 22:42:30 (GMT) | 
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-18 22:42:30 (GMT) | 
| commit | b0b3bffe8b51c96f24095bdbf26b67c31403cd31 (patch) | |
| tree | 1c224899505c94a2286a58bccfa514a017507dc5 /Lib/test/test_subprocess.py | |
| parent | c4caa9c4009ed344f903f2b39956720f473dd676 (diff) | |
| download | cpython-b0b3bffe8b51c96f24095bdbf26b67c31403cd31.zip cpython-b0b3bffe8b51c96f24095bdbf26b67c31403cd31.tar.gz cpython-b0b3bffe8b51c96f24095bdbf26b67c31403cd31.tar.bz2 | |
Merged revisions 84883 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
  r84883 | antoine.pitrou | 2010-09-19 00:38:48 +0200 (dim., 19 sept. 2010) | 3 lines
  Issue #9895: speed up test_subprocess
........
Diffstat (limited to 'Lib/test/test_subprocess.py')
| -rw-r--r-- | Lib/test/test_subprocess.py | 44 | 
1 files changed, 32 insertions, 12 deletions
| diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index d056ac3..4f9cceb 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -454,20 +454,40 @@ class ProcessTestCase(BaseTestCase):      def test_no_leaking(self):          # Make sure we leak no resources -        if not hasattr(test_support, "is_resource_enabled") \ -               or test_support.is_resource_enabled("subprocess") and not mswindows: +        if not mswindows:              max_handles = 1026 # too much for most UNIX systems          else: -            max_handles = 65 -        for i in range(max_handles): -            p = subprocess.Popen([sys.executable, "-c", -                    "import sys;sys.stdout.write(sys.stdin.read())"], -                    stdin=subprocess.PIPE, -                    stdout=subprocess.PIPE, -                    stderr=subprocess.PIPE) -            data = p.communicate("lime")[0] -            self.assertEqual(data, "lime") - +            max_handles = 2050 # too much for (at least some) Windows setups +        handles = [] +        try: +            for i in range(max_handles): +                try: +                    handles.append(os.open(test_support.TESTFN, +                                           os.O_WRONLY | os.O_CREAT)) +                except OSError as e: +                    if e.errno != errno.EMFILE: +                        raise +                    break +            else: +                self.skipTest("failed to reach the file descriptor limit " +                    "(tried %d)" % max_handles) +            # Close a couple of them (should be enough for a subprocess) +            for i in range(10): +                os.close(handles.pop()) +            # Loop creating some subprocesses. If one of them leaks some fds, +            # the next loop iteration will fail by reaching the max fd limit. +            for i in range(15): +                p = subprocess.Popen([sys.executable, "-c", +                                      "import sys;" +                                      "sys.stdout.write(sys.stdin.read())"], +                                     stdin=subprocess.PIPE, +                                     stdout=subprocess.PIPE, +                                     stderr=subprocess.PIPE) +                data = p.communicate(b"lime")[0] +                self.assertEqual(data, b"lime") +        finally: +            for h in handles: +                os.close(h)      def test_list2cmdline(self):          self.assertEqual(subprocess.list2cmdline(['a b c', 'd', 'e']), | 
