Home | Trees | Indices | Help |
---|
|
1 # Copyright (c) 2002-2011 IronPort Systems and Cisco Systems 2 # 3 # Permission is hereby granted, free of charge, to any person obtaining a copy 4 # of this software and associated documentation files (the "Software"), to deal 5 # in the Software without restriction, including without limitation the rights 6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 # copies of the Software, and to permit persons to whom the Software is 8 # furnished to do so, subject to the following conditions: 9 # 10 # The above copyright notice and this permission notice shall be included in 11 # all copies or substantial portions of the Software. 12 # 13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 # SOFTWARE. 20 21 # $Header: //prod/main/ap/shrapnel/coro/signal_handler.py#8 $ 22 23 """Signal handler.""" 24 25 __version__ = '$Revision: #8 $' 26 27 import coro 28 import signal 29 import os 30 31 UNAME = os.uname()[0] 3234 """Register a signal handler. 35 36 :Parameters: 37 - `signum`: The signal number to register. 38 - `handler`: A callable object that takes one parameter which is the 39 signal number that was triggered. 40 - `once_only`: If True, will only trigger once, and then disable the 41 signal handler. Defaults to False. 42 43 :Exceptions: 44 - `coro.SimultaneousError`: Another handler is already registered for 45 this signal. 46 """ 47 48 if UNAME in ('FreeBSD', 'Darwin'): 49 # first, turn *off* normal signal handling... 50 signal.signal (signum, signal.SIG_IGN) 51 # register with kqueue 52 flags = coro.EV.ADD 53 if once_only: 54 flags |= coro.EV.ONESHOT 55 k_handler = lambda x: handler(x.ident) 56 coro.set_handler ((signum, coro.EVFILT.SIGNAL), k_handler, flags) 57 else: 58 signal.signal(signum, handler)59 60 61 # alias for backward compatibility 62 register_signal_handler = register 63
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Feb 16 18:06:45 2012 | http://epydoc.sourceforge.net |