當前位置: 首頁>>代碼示例>>Python>>正文


Python signal.SIGPROF屬性代碼示例

本文整理匯總了Python中signal.SIGPROF屬性的典型用法代碼示例。如果您正苦於以下問題:Python signal.SIGPROF屬性的具體用法?Python signal.SIGPROF怎麽用?Python signal.SIGPROF使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在signal的用法示例。


在下文中一共展示了signal.SIGPROF屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGPROF [as 別名]
def run(self, profiler):
        weak_profiler = weakref.proxy(profiler)
        handle = functools.partial(self.handle_signal, weak_profiler)
        t = self.interval
        with deferral() as defer:
            prev_handle = signal.signal(signal.SIGPROF, handle)
            if prev_handle == signal.SIG_DFL:
                # sometimes the process receives SIGPROF although the sampler
                # unsets the itimer.  If the previous handler was SIG_DFL, the
                # process will crash when received SIGPROF.  To prevent this
                # risk, it makes the process to ignore SIGPROF when it isn't
                # running if the previous handler was SIG_DFL.
                prev_handle = signal.SIG_IGN
            defer(signal.signal, signal.SIGPROF, prev_handle)
            prev_itimer = signal.setitimer(signal.ITIMER_PROF, t, t)
            defer(signal.setitimer, signal.ITIMER_PROF, *prev_itimer)
            yield 
開發者ID:what-studio,項目名稱:profiling,代碼行數:19,代碼來源:samplers.py

示例2: test_itimer_prof

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGPROF [as 別名]
def test_itimer_prof(self):
        self.itimer = signal.ITIMER_PROF
        signal.signal(signal.SIGPROF, self.sig_prof)
        signal.setitimer(self.itimer, 0.2, 0.2)

        start_time = time.monotonic()
        while time.monotonic() - start_time < 60.0:
            # do some work
            _ = pow(12345, 67890, 10000019)
            if signal.getitimer(self.itimer) == (0.0, 0.0):
                break # sig_prof handler stopped this itimer
        else: # Issue 8424
            self.skipTest("timeout: likely cause: machine too slow or load too "
                          "high")

        # profiling itimer should be (0.0, 0.0) now
        self.assertEqual(signal.getitimer(self.itimer), (0.0, 0.0))
        # and the handler should have been called
        self.assertEqual(self.hndl_called, True) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:21,代碼來源:test_signal.py

示例3: __init__

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGPROF [as 別名]
def __init__(self, global_config):
        self.global_config = global_config
        self.ccmap = []
        self.el = Timeout(self.GClector, 60, -1)
        Signal(SIGHUP, self.discAll, SIGHUP)
        Signal(SIGUSR2, self.toggleDebug, SIGUSR2)
        Signal(SIGPROF, self.safeRestart, SIGPROF)
        Signal(SIGTERM, self.safeStop, SIGTERM)
        #gc.disable()
        #gc.set_debug(gc.DEBUG_STATS)
        #gc.set_threshold(0)
        #print gc.collect() 
開發者ID:sippy,項目名稱:b2bua,代碼行數:14,代碼來源:b2bua_radius.py

示例4: test_itimer_sampler

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGPROF [as 別名]
def test_itimer_sampler():
    assert signal.getsignal(signal.SIGPROF) == signal.SIG_DFL
    try:
        _test_sampling_profiler(ItimerSampler(0.0001))
        # no crash caused by SIGPROF.
        assert signal.getsignal(signal.SIGPROF) == signal.SIG_IGN
        for x in range(10):
            os.kill(os.getpid(), signal.SIGPROF)
        # respect custom handler.
        handler = lambda *x: x
        signal.signal(signal.SIGPROF, handler)
        _test_sampling_profiler(ItimerSampler(0.0001))
        assert signal.getsignal(signal.SIGPROF) == handler
    finally:
        signal.signal(signal.SIGPROF, signal.SIG_DFL) 
開發者ID:what-studio,項目名稱:profiling,代碼行數:17,代碼來源:test_sampling.py

示例5: __init__

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGPROF [as 別名]
def __init__(self, global_config):
        self.global_config = global_config
        self.ccmap = []
        self.el = Timeout(self.GClector, 60, -1)
        Signal(SIGHUP, self.discAll, SIGHUP)
        Signal(SIGUSR2, self.toggleDebug, SIGUSR2)
        Signal(SIGPROF, self.safeRestart, SIGPROF)
        #gc.disable()
        #gc.set_debug(gc.DEBUG_STATS)
        #gc.set_threshold(0)
        #print gc.collect() 
開發者ID:hgascon,項目名稱:pulsar,代碼行數:13,代碼來源:b2bua_radius.py

示例6: test_stress_delivery_dependent

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGPROF [as 別名]
def test_stress_delivery_dependent(self):
        """
        This test uses dependent signal handlers.
        """
        N = self.decide_itimer_count()
        sigs = []

        def first_handler(signum, frame):
            # 1e-6 is the minimum non-zero value for `setitimer()`.
            # Choose a random delay so as to improve chances of
            # triggering a race condition.  Ideally the signal is received
            # when inside critical signal-handling routines such as
            # Py_MakePendingCalls().
            signal.setitimer(signal.ITIMER_REAL, 1e-6 + random.random() * 1e-5)

        def second_handler(signum=None, frame=None):
            sigs.append(signum)

        # Here on Linux, SIGPROF > SIGALRM > SIGUSR1.  By using both
        # ascending and descending sequences (SIGUSR1 then SIGALRM,
        # SIGPROF then SIGALRM), we maximize chances of hitting a bug.
        self.setsig(signal.SIGPROF, first_handler)
        self.setsig(signal.SIGUSR1, first_handler)
        self.setsig(signal.SIGALRM, second_handler)  # for ITIMER_REAL

        expected_sigs = 0
        deadline = time.monotonic() + 15.0

        while expected_sigs < N:
            os.kill(os.getpid(), signal.SIGPROF)
            expected_sigs += 1
            # Wait for handlers to run to avoid signal coalescing
            while len(sigs) < expected_sigs and time.monotonic() < deadline:
                time.sleep(1e-5)

            os.kill(os.getpid(), signal.SIGUSR1)
            expected_sigs += 1
            while len(sigs) < expected_sigs and time.monotonic() < deadline:
                time.sleep(1e-5)

        # All ITIMER_REAL signals should have been delivered to the
        # Python handler
        self.assertEqual(len(sigs), N, "Some signals were lost") 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:45,代碼來源:test_signal.py


注:本文中的signal.SIGPROF屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。