• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python signal.getsignal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中signal.getsignal函数的典型用法代码示例。如果您正苦于以下问题:Python getsignal函数的具体用法?Python getsignal怎么用?Python getsignal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了getsignal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:c0sco,项目名称:bounded,代码行数:30,代码来源:bounded.py


示例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)
开发者ID:fluxid,项目名称:sandboxed,代码行数:27,代码来源:utils.py


示例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)
开发者ID:MichaelBlume,项目名称:pypy,代码行数:28,代码来源:test_signal.py


示例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)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:7,代码来源:test_break.py


示例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)
开发者ID:Eyepea,项目名称:cpython,代码行数:7,代码来源:test_signal.py


示例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)
开发者ID:GrimDerp,项目名称:robotframework,代码行数:7,代码来源:test_run_and_rebot.py


示例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)
开发者ID:jschementi,项目名称:iron,代码行数:29,代码来源:test_break.py


示例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)
开发者ID:zenlambda,项目名称:appengine-python3,代码行数:7,代码来源:shutdown_test.py


示例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
开发者ID:jcorbin,项目名称:better-subprocess,代码行数:27,代码来源:test_reaper.py


示例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
开发者ID:ildus,项目名称:wsgid,代码行数:33,代码来源:cli.py


示例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)
开发者ID:anupkrish24,项目名称:kaLLogs,代码行数:25,代码来源:test_break.py


示例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)
开发者ID:douglas,项目名称:thumbor,代码行数:27,代码来源:server.py


示例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))
开发者ID:89sos98,项目名称:main,代码行数:25,代码来源:signal_test.py


示例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
开发者ID:HelioGuilherme66,项目名称:robotframework,代码行数:7,代码来源:signalhandler.py


示例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__)
开发者ID:fanfannothing,项目名称:pebble,代码行数:7,代码来源:test_pebble.py


示例16: test_termination_handler

    def test_termination_handler(self):
        """ Events.terminate() exception test """

        EventHandler.terminate()

        self.assertIs('kill_process', signal.getsignal(signal.SIGTSTP).__name__)
        self.assertTrue(None is not signal.getsignal(signal.SIGTERM))
开发者ID:stanislav-web,项目名称:OpenDoor,代码行数:7,代码来源:test_lib_events.py


示例17: test_timeout_fail

 def test_timeout_fail(self):
     tests = ['timeout.TimeoutTest.testTimeoutFail']
     msg = "OETestTimeout test didn't timeout as expected"
     alarm_signal = signal.getsignal(signal.SIGALRM)
     tc = self._testLoader(modules=self.modules, tests=tests)
     self.assertFalse(tc.runTests().wasSuccessful(), msg=msg)
     msg = "OETestTimeout didn't restore SIGALRM"
     self.assertIs(alarm_signal, signal.getsignal(signal.SIGALRM), msg=msg)
开发者ID:openembedded,项目名称:openembedded-core,代码行数:8,代码来源:test_decorators.py


示例18: 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)
     suite = TestSuite(name='My Suite')
     suite.tests.create(name='My Test').keywords.create('Log', args=['Hi!'])
     run(suite)
     assert_equals(signal.getsignal(signal.SIGINT), self.orig_sigint)
     assert_equals(signal.getsignal(signal.SIGTERM), my_sigterm)
开发者ID:userzimmermann,项目名称:robotframework-python3,代码行数:8,代码来源:test_running.py


示例19: test_replace_handler_and_restore_nested

 def test_replace_handler_and_restore_nested(self):
     with register_sigint_fallback(lambda: None):
         new_handler = signal.getsignal(signal.SIGINT)
         self.assertNotEqual(new_handler, signal.default_int_handler)
         with register_sigint_fallback(lambda: None):
             self.assertTrue(signal.getsignal(signal.SIGINT) is new_handler)
     self.assertEqual(
         signal.getsignal(signal.SIGINT), signal.default_int_handler)
开发者ID:GNOME,项目名称:pygobject,代码行数:8,代码来源:test_ossig.py


示例20: test_restores_handler

    def test_restores_handler(self):
        handler_1 = lambda signum, frame: None
        handler_2 = lambda s, f: True
        with dbg._let_signal(signal.SIGALRM, handler_1):
            with dbg._let_signal(signal.SIGALRM, handler_2):
                self.assertEqual(signal.getsignal(signal.SIGALRM), handler_2)

            self.assertEqual(signal.getsignal(signal.SIGALRM), handler_1)
开发者ID:ieure,项目名称:tillicum,代码行数:8,代码来源:test_debug.py



注:本文中的signal.getsignal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python signal.pause函数代码示例发布时间:2022-05-27
下一篇:
Python signal.getitimer函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap