bpo-31009: Fix support.fd_count() on Windows (#2862)

* bpo-31009: Fix support.fd_count() on Windows

On Windows, test.support.fd_count() now calls
msvcrt.CrtSetReportMode() to not kill the process nor log any error
on stderr on os.dup(fd) if the file descriptor is invalid.

* Fix for release mode
This commit is contained in:
Victor Stinner 2017-07-25 17:45:53 +02:00 committed by GitHub
parent 90addd6d1c
commit 302bbbe9ba
2 changed files with 43 additions and 29 deletions

View file

@ -835,22 +835,10 @@ class ArgsTestCase(BaseTestCase):
import os
import unittest
# Issue #25306: Disable popups and logs to stderr on assertion
# failures in MSCRT
try:
import msvcrt
msvcrt.CrtSetReportMode
except (ImportError, AttributeError):
# no Windows, o release build
pass
else:
for m in [msvcrt.CRT_WARN, msvcrt.CRT_ERROR, msvcrt.CRT_ASSERT]:
msvcrt.CrtSetReportMode(m, 0)
class FDLeakTest(unittest.TestCase):
def test_leak(self):
fd = os.open(__file__, os.O_RDONLY)
# bug: never cloes the file descriptor
# bug: never close the file descriptor
""")
self.check_leak(code, 'file descriptors')