From: Ben Darnell Date: Sun, 22 May 2016 00:23:51 +0000 (-0400) Subject: Fix error raised in set_close_exec on windows X-Git-Tag: v4.4.0b1~18^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b49c87a715a87b2c31f4ba8e664379c783ff68cc;p=thirdparty%2Ftornado.git Fix error raised in set_close_exec on windows This slightly improves error messaging when tornado.process.Subprocess is used in windows. Fixes #1703 --- diff --git a/tornado/platform/windows.py b/tornado/platform/windows.py index 92295fc6c..9a319f277 100644 --- a/tornado/platform/windows.py +++ b/tornado/platform/windows.py @@ -17,4 +17,4 @@ HANDLE_FLAG_INHERIT = 0x00000001 def set_close_exec(fd): success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0) if not success: - raise ctypes.GetLastError() + raise ctypes.WinError() diff --git a/tornado/test/runtests.py b/tornado/test/runtests.py index 3b22d396e..ca82d66b9 100644 --- a/tornado/test/runtests.py +++ b/tornado/test/runtests.py @@ -53,6 +53,7 @@ TEST_MODULES = [ 'tornado.test.util_test', 'tornado.test.web_test', 'tornado.test.websocket_test', + 'tornado.test.windows_test', 'tornado.test.wsgi_test', ] diff --git a/tornado/test/windows_test.py b/tornado/test/windows_test.py new file mode 100644 index 000000000..26e01614d --- /dev/null +++ b/tornado/test/windows_test.py @@ -0,0 +1,25 @@ +import functools +import os +import socket +import unittest + +from tornado.platform.auto import set_close_exec + +skipIfNonWindows = unittest.skipIf(os.name != 'nt', 'non-windows platform') + +@skipIfNonWindows +class WindowsTest(unittest.TestCase): + def test_set_close_exec(self): + # set_close_exec works with sockets. + s = socket.socket() + self.addCleanup(s.close) + set_close_exec(s.fileno()) + + # But it doesn't work with pipes. + r, w = os.pipe() + self.addCleanup(functools.partial(os.close, r)) + self.addCleanup(functools.partial(os.close, w)) + with self.assertRaises(WindowsError) as cm: + set_close_exec(r) + ERROR_INVALID_HANDLE = 6 + self.assertEqual(cm.exception.winerror, ERROR_INVALID_HANDLE)