[Python-checkins] r85104 - in python/branches/py3k-issue9978/Lib/test: test_os.py win_console_handler.py

hirokazu.yamamoto python-checkins at python.org
Wed Sep 29 14:36:15 CEST 2010


Author: hirokazu.yamamoto
Date: Wed Sep 29 14:36:14 2010
New Revision: 85104
Log:
Wait for win_console_handler reaches before dead loop.
(Otherwise, test_os.py didn't fail on slow machine because
process was killed before wintypes.WINFUNCTYPE was reached)
# I suppose Win32 CreateEvent is better.
Modified:
 python/branches/py3k-issue9978/Lib/test/test_os.py
 python/branches/py3k-issue9978/Lib/test/win_console_handler.py
Modified: python/branches/py3k-issue9978/Lib/test/test_os.py
==============================================================================
--- python/branches/py3k-issue9978/Lib/test/test_os.py	(original)
+++ python/branches/py3k-issue9978/Lib/test/test_os.py	Wed Sep 29 14:36:14 2010
@@ -13,6 +13,7 @@
 import shutil
 from test import support
 import contextlib
+from win_console_handler import create_mmap
 
 # Detect whether we're on a Linux system that uses the (now outdated
 # and unmaintained) linuxthreads threading library. There's an issue
@@ -1029,13 +1030,16 @@
 self._kill(100)
 
 def _kill_with_event(self, event, name):
+ m = create_mmap()
+ m[0] = 0
 # Run a script which has console control handling enabled.
 proc = subprocess.Popen([sys.executable,
 os.path.join(os.path.dirname(__file__),
 "win_console_handler.py")],
 creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
 # Let the interpreter startup before we send signals. See #3137.
- time.sleep(0.5)
+ while m[0] == 0:
+ time.sleep(0.5)
 os.kill(proc.pid, event)
 # proc.send_signal(event) could also be done here.
 # Allow time for the signal to be passed and the process to exit.
Modified: python/branches/py3k-issue9978/Lib/test/win_console_handler.py
==============================================================================
--- python/branches/py3k-issue9978/Lib/test/win_console_handler.py	(original)
+++ python/branches/py3k-issue9978/Lib/test/win_console_handler.py	Wed Sep 29 14:36:14 2010
@@ -8,36 +8,46 @@
 similar example in C.
 """
 
-from ctypes import wintypes
-import signal
-import ctypes
-
-# Function prototype for the handler function. Returns BOOL, takes a DWORD.
-HandlerRoutine = wintypes.WINFUNCTYPE(wintypes.BOOL, wintypes.DWORD)
-
-def _ctrl_handler(sig):
- """Handle a sig event and return 0 to terminate the process"""
- if sig == signal.CTRL_C_EVENT:
- pass
- elif sig == signal.CTRL_BREAK_EVENT:
- pass
- else:
- print("UNKNOWN EVENT")
- return 0
+import mmap
 
-ctrl_handler = HandlerRoutine(_ctrl_handler)
+def create_mmap():
+ return mmap.mmap(-1, 1, "Python/Lib/test/win_console_handler.py")
 
+if __name__ == "__main__":
+ from ctypes import wintypes
+ import signal
+ import ctypes
+
+ # Function prototype for the handler function. Returns BOOL, takes a DWORD.
+ HandlerRoutine = wintypes.WINFUNCTYPE(wintypes.BOOL, wintypes.DWORD)
+
+ def _ctrl_handler(sig):
+ """Handle a sig event and return 0 to terminate the process"""
+ if sig == signal.CTRL_C_EVENT:
+ pass
+ elif sig == signal.CTRL_BREAK_EVENT:
+ pass
+ else:
+ print("UNKNOWN EVENT")
+ return 0
+
+ ctrl_handler = HandlerRoutine(_ctrl_handler)
+
+
+ SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
+ SetConsoleCtrlHandler.argtypes = (HandlerRoutine, wintypes.BOOL)
+ SetConsoleCtrlHandler.restype = wintypes.BOOL
 
-SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
-SetConsoleCtrlHandler.argtypes = (HandlerRoutine, wintypes.BOOL)
-SetConsoleCtrlHandler.restype = wintypes.BOOL
 
-if __name__ == "__main__":
 # Add our console control handling function with value 1
 if not SetConsoleCtrlHandler(ctrl_handler, 1):
 print("Unable to add SetConsoleCtrlHandler")
 exit(-1)
 
+ # Awake waiting main process
+ m = create_mmap()
+ m[0] = 1
+
 # Do nothing but wait for the signal
 while True:
 pass


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /