comparison mercurial/win32.py @ 14237:4d684d8210a1

rename util.set_signal_handler to setsignalhandler
author Adrian Buehlmann <adrian@cadifra.com>
date Fri, 06 May 2011 15:41:04 +0200
parents e949a008999d
children e1db8a00188b
comparison
equal deleted inserted replaced
14236:e949a008999d 14237:4d684d8210a1
237 if not adv.GetUserNameA(ctypes.byref(buf), ctypes.byref(size)): 237 if not adv.GetUserNameA(ctypes.byref(buf), ctypes.byref(size)):
238 raise ctypes.WinError() 238 raise ctypes.WinError()
239 return buf.value 239 return buf.value
240 240
241 _SIGNAL_HANDLER = ctypes.WINFUNCTYPE(_BOOL, _DWORD) 241 _SIGNAL_HANDLER = ctypes.WINFUNCTYPE(_BOOL, _DWORD)
242 _signal_handler = [] 242 _signalhandler = []
243 243
244 def set_signal_handler(): 244 def setsignalhandler():
245 '''Register a termination handler for console events including 245 '''Register a termination handler for console events including
246 CTRL+C. python signal handlers do not work well with socket 246 CTRL+C. python signal handlers do not work well with socket
247 operations. 247 operations.
248 ''' 248 '''
249 def handler(event): 249 def handler(event):
250 _kernel32.ExitProcess(1) 250 _kernel32.ExitProcess(1)
251 251
252 if _signal_handler: 252 if _signalhandler:
253 return # already registered 253 return # already registered
254 h = _SIGNAL_HANDLER(handler) 254 h = _SIGNAL_HANDLER(handler)
255 _signal_handler.append(h) # needed to prevent garbage collection 255 _signalhandler.append(h) # needed to prevent garbage collection
256 if not _kernel32.SetConsoleCtrlHandler(h, True): 256 if not _kernel32.SetConsoleCtrlHandler(h, True):
257 raise ctypes.WinError() 257 raise ctypes.WinError()
258 258
259 _WNDENUMPROC = ctypes.WINFUNCTYPE(_BOOL, _HWND, _LPARAM) 259 _WNDENUMPROC = ctypes.WINFUNCTYPE(_BOOL, _HWND, _LPARAM)
260 260