本文整理汇总了Python中signal.getsignal函数的典型用法代码示例。如果您正苦于以下问题:Python getsignal函数的具体用法?Python getsignal怎么用?Python getsignal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getsignal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addBlackhole
def addBlackhole(srcip):
""" Add an IP to blackhole.conf and tell BIND to reread its config file. """
if opt.test:
return
try:
# Go to the end of the file and write the IP, and close out the blackhole block
f = open(opt.blackhole, 'r+')
f.seek(-3, 2)
f.writelines([srcip, ';\n', '};\n'])
f.close()
os.chown(opt.blackhole, uid, gid)
except:
log("Can't add entry to blackhole file: %s" % opt.blackhole)
return
global gtimer
if gtimer and int(time.time()) - int(gtimer) > opt.throttle:
rndcReconfig()
gtimer = time.time()
signal.alarm(0)
signal.signal(signal.SIGALRM, signal.SIG_IGN)
else:
if signal.getsignal(signal.SIGALRM) == 0 or signal.getsignal(signal.SIGALRM) == 1:
signal.signal(signal.SIGALRM, alarmHandler)
signal.alarm(opt.throttle)
return
示例2: clone_and_wait
def clone_and_wait(callback, flags):
pid = lowlevel.clone(flags)
assert pid is not None
if pid:
def handle_signal(signum, frame):
patient_terminate(pid, wait_flags = const.WALL)
old_term = signal.getsignal(signal.SIGTERM)
old_int = signal.getsignal(signal.SIGINT)
signal.signal(signal.SIGTERM, handle_signal)
signal.signal(signal.SIGINT, handle_signal)
wait_for_pid(pid, flags = const.WALL)
signal.signal(signal.SIGTERM, old_term)
signal.signal(signal.SIGINT, old_int)
else:
status = 1
try:
if flags ^ const.CLONE_NEWPID:
assert lowlevel.getpid() == 1
status = callback()
status = int(status) if status else 0
except:
sys.excepthook(*sys.exc_info())
finally:
os._exit(status)
示例3: test_getsignal
def test_getsignal(self):
"""
Test that signal.getsignal returns the currently installed handler.
"""
from signal import getsignal, signal, SIGINT, SIG_DFL, SIG_IGN
def handler(*a):
pass
try:
assert getsignal(SIGINT) == SIG_DFL
signal(SIGINT, SIG_DFL)
assert getsignal(SIGINT) == SIG_DFL
signal(SIGINT, SIG_IGN)
assert getsignal(SIGINT) == SIG_IGN
signal(SIGINT, handler)
assert getsignal(SIGINT) is handler
finally:
signal(SIGINT, SIG_DFL)
raises(ValueError, getsignal, 4444)
raises(ValueError, signal, 4444, lambda *args: None)
import sys
if sys.platform == 'win32':
raises(ValueError, signal, 42, lambda *args: None)
else:
signal(42, lambda *args: None)
signal(42, SIG_DFL)
示例4: testRemoveHandler
def testRemoveHandler(self):
default_handler = signal.getsignal(signal.SIGINT)
unittest.installHandler()
unittest.removeHandler()
self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)
unittest.removeHandler()
self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)
示例5: test_getsignal
def test_getsignal(self):
hup = signal.signal(signal.SIGHUP, self.trivial_signal_handler)
self.assertIsInstance(hup, signal.Handlers)
self.assertEqual(signal.getsignal(signal.SIGHUP),
self.trivial_signal_handler)
signal.signal(signal.SIGHUP, hup)
self.assertEqual(signal.getsignal(signal.SIGHUP), hup)
示例6: test_original_signal_handlers_are_restored
def test_original_signal_handlers_are_restored(self):
my_sigterm = lambda signum, frame: None
signal.signal(signal.SIGTERM, my_sigterm)
run(join(ROOT, 'atest', 'testdata', 'misc', 'pass_and_fail.txt'),
stdout=StringIO(), output=None, log=None, report=None)
assert_equals(signal.getsignal(signal.SIGINT), self.orig_sigint)
assert_equals(signal.getsignal(signal.SIGTERM), my_sigterm)
示例7: testTwoResults
def testTwoResults(self):
if due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/28171"):
return
unittest.installHandler()
result = unittest.TestResult()
unittest.registerResult(result)
new_handler = signal.getsignal(signal.SIGINT)
result2 = unittest.TestResult()
unittest.registerResult(result2)
self.assertEqual(signal.getsignal(signal.SIGINT), new_handler)
result3 = unittest.TestResult()
def test(result):
pid = os.getpid()
os.kill(pid, signal.SIGINT)
try:
test(result)
except KeyboardInterrupt:
self.fail("KeyboardInterrupt not handled")
if not due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/28171"):
self.assertTrue(result.shouldStop)
self.assertTrue(result2.shouldStop)
self.assertFalse(result3.shouldStop)
示例8: setUp
def setUp(self):
self.mox = mox.Mox()
self.mox.StubOutWithMock(os, 'abort')
shutdown._shutting_down = False
shutdown._num_terminate_requests = 0
self._sigint_handler = signal.getsignal(signal.SIGINT)
self._sigterm_handler = signal.getsignal(signal.SIGTERM)
示例9: test_sigchld
def test_sigchld():
r = reaper.Reaper()
old_sigchld = signal.getsignal(signal.SIGCHLD)
r.hookup_sigchld()
assert r.old_sigchld is old_sigchld
assert signal.getsignal(signal.SIGCHLD) == reaper.theReaper.handle_sigchld
del r
waiting = [DelayedExitFork(i, (i % 32) / 32) for i in range(256)]
while waiting:
signal.pause()
i = 0
while i < len(waiting):
if waiting[i].obit is not None:
f = waiting.pop(i)
assert f.obit.pid == f.pid
assert f.obit.exitstatus == f.expectedstatus
assert f.obit.termsig is None
assert f.obit.stopsig is None
assert f.obit.coredump is False
else:
i += 1
reaper.theReaper.unhookup_sigchld()
assert signal.getsignal(signal.SIGCHLD) is old_sigchld
reaper.theReaper = None
示例10: _create_daemon_options
def _create_daemon_options(self, options):
daemon = {'detach_process': not options.no_daemon}
daemon.update({ 'stdin': sys.stdin,
'stdout': sys.stdout,
'stderr': sys.stderr})
if options.no_daemon:
# If we are not a daemon we must maintain the basic signal handlers
daemon.update({'signal_map': {
signal.SIGTTIN: signal.getsignal(signal.SIGTTIN),
signal.SIGTTOU: signal.getsignal(signal.SIGTTOU),
signal.SIGTSTP: signal.getsignal(signal.SIGTSTP),
signal.SIGTERM: signal.getsignal(signal.SIGTERM)
}})
else:
daemon.update({'signal_map':
{signal.SIGTERM: signal.getsignal(signal.SIGTERM)}
})
daemon.update({'uid': os.getuid(), 'gid': os.getgid()})
if options.app_path:
full_path = options.app_path
stat = os.stat(full_path)
daemon.update({'uid': stat.st_uid,
'gid': stat.st_gid})
if options.chroot:
full_path = options.app_path
stat = os.stat(full_path)
daemon.update({'chroot_directory': full_path,
'uid': stat.st_uid,
'gid': stat.st_gid})
return daemon
示例11: testTwoResults
def testTwoResults(self):
unittest2.installHandler()
result = unittest2.TestResult()
unittest2.registerResult(result)
new_handler = signal.getsignal(signal.SIGINT)
result2 = unittest2.TestResult()
unittest2.registerResult(result2)
self.assertEqual(signal.getsignal(signal.SIGINT), new_handler)
result3 = unittest2.TestResult()
def test(result):
pid = os.getpid()
os.kill(pid, signal.SIGINT)
try:
test(result)
except KeyboardInterrupt:
self.fail("KeyboardInterrupt not handled")
self.assertTrue(result.shouldStop)
self.assertTrue(result2.shouldStop)
self.assertFalse(result3.shouldStop)
示例12: main
def main():
'''Runs thumbor server with the specified arguments.'''
global server
global ip
global port
global conf
parser = optparse.OptionParser(usage="thumbor or type thumbor -h (--help) for help", description=__doc__, version=__version__)
parser.add_option("-p", "--port", type="int", dest="port", default=8888, help = "The port to run this thumbor instance at [default: %default]." )
parser.add_option("-i", "--ip", dest="ip", default="0.0.0.0", help = "The host address to run this thumbor instance at [default: %default]." )
parser.add_option("-c", "--conf", dest="conf", default="", help = "The path of the configuration file to use for this thumbor instance [default: %default]." )
parser.add_option("-l", "--log-level", dest="log_level", default="warning", help = "The log level to be used. Possible values are: debug, info, warning, error, critical or notset. [default: %default]." )
parser.add_option("-a", "--app", dest="app", default=None, help = "A custom app to use for this thumbor server in case you subclassed ThumborServiceApp [default: %default]." )
(options, args) = parser.parse_args()
if not signal.getsignal(signal.SIGHUP):
signal.signal(signal.SIGHUP, handle_sighup)
if not signal.getsignal(signal.SIGTERM):
signal.signal(signal.SIGTERM, handle_sigterm)
port = options.port
ip = options.ip
conf = options.conf or None
log_level = options.log_level
run_app(ip, port, conf, log_level, options.app)
示例13: test_signal_signal
def test_signal_signal():
WORKING_CASES = SUPPORTED_SIGNALS + [6]
WEIRD_CASES = {
6: None,
2: signal.default_int_handler}
for x in WORKING_CASES:
#Ideal handler signature
def a(signum, frame):
return x
ret_val = signal.signal(x, a)
if x not in WEIRD_CASES.keys():
AreEqual(ret_val, signal.SIG_DFL)
else:
AreEqual(ret_val, WEIRD_CASES[x])
AreEqual(a, signal.getsignal(x))
#Strange handler signatures
class KNew(object):
def __call__(self, *args, **kwargs):
pass
a = KNew()
ret_val = signal.signal(signal.SIGBREAK, a)
AreEqual(a, signal.getsignal(signal.SIGBREAK))
示例14: __enter__
def __enter__(self):
if self._can_register_signal:
self._orig_sigint = signal.getsignal(signal.SIGINT)
self._orig_sigterm = signal.getsignal(signal.SIGTERM)
for signum in signal.SIGINT, signal.SIGTERM:
self._register_signal_handler(signum)
return self
示例15: test_sighandler_multiple
def test_sighandler_multiple(self):
"""Sighandler installs SIGFPE and SIGIO."""
if os.name != 'nt':
self.assertEqual(signal.getsignal(signal.SIGFPE).__name__,
signals_handler.__name__)
self.assertEqual(signal.getsignal(signal.SIGIO).__name__,
signals_handler.__name__)