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


Python sys.setcheckinterval方法代碼示例

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


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

示例1: test_enumerate_after_join

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def test_enumerate_after_join(self):
        # Try hard to trigger #1703448: a thread is still returned in
        # threading.enumerate() after it has been join()ed.
        enum = threading.enumerate
        old_interval = sys.getcheckinterval()
        try:
            for i in xrange(1, 100):
                # Try a couple times at each thread-switching interval
                # to get more interleavings.
                sys.setcheckinterval(i // 5)
                t = threading.Thread(target=lambda: None)
                t.start()
                t.join()
                l = enum()
                self.assertNotIn(t, l,
                    "#1703448 triggered after %d trials: %s" % (i, l))
        finally:
            sys.setcheckinterval(old_interval) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_threading.py

示例2: test_is_alive_after_fork

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def test_is_alive_after_fork(self):
        # Try hard to trigger #18418: is_alive() could sometimes be True on
        # threads that vanished after a fork.
        old_interval = sys.getcheckinterval()

        # Make the bug more likely to manifest.
        sys.setcheckinterval(10)

        try:
            for i in range(20):
                t = threading.Thread(target=lambda: None)
                t.start()
                pid = os.fork()
                if pid == 0:
                    os._exit(1 if t.is_alive() else 0)
                else:
                    t.join()
                    pid, status = os.waitpid(pid, 0)
                    self.assertEqual(0, status)
        finally:
            sys.setcheckinterval(old_interval) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:23,代碼來源:test_threading.py

示例3: collect_in_thread

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def collect_in_thread(period=0.001):
    """
    Ensure GC collections happen in a different thread, at a high frequency.
    """
    threading = test_support.import_module('threading')
    please_stop = False

    def collect():
        while not please_stop:
            time.sleep(period)
            gc.collect()

    with test_support.disable_gc():
        old_interval = sys.getcheckinterval()
        sys.setcheckinterval(20)
        t = threading.Thread(target=collect)
        t.start()
        try:
            yield
        finally:
            please_stop = True
            t.join()
            sys.setcheckinterval(old_interval) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:test_weakref.py

示例4: adjust_balance_concurrently

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def adjust_balance_concurrently(self, account):
        def transact():
            account.deposit(5)
            time.sleep(0.001)
            account.withdraw(5)

        # Greatly improve the chance of an operation being interrupted
        # by thread switch, thus testing synchronization effectively
        try:
            sys.setswitchinterval(1e-12)
        except AttributeError:
            # For Python 2 compatibility
            sys.setcheckinterval(1)

        threads = [threading.Thread(target=transact) for _ in range(1000)]
        for thread in threads:
            thread.start()
        for thread in threads:
            thread.join()

    # Utility functions 
開發者ID:exercism,項目名稱:python,代碼行數:23,代碼來源:bank_account_test.py

示例5: setUp

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def setUp(self):
        """
        Reduce the CPython check interval so that thread switches happen much
        more often, hopefully exercising more possible race conditions.  Also,
        delay actual test startup until the reactor has been started.
        """
        if hasattr(sys, 'getcheckinterval'):
            self.addCleanup(sys.setcheckinterval, sys.getcheckinterval())
            sys.setcheckinterval(7)
        # XXX This is a trial hack.  We need to make sure the reactor
        # actually *starts* for isInIOThread() to have a meaningful result.
        # Returning a Deferred here should force that to happen, if it has
        # not happened already.  In the future, this should not be
        # necessary.
        d = defer.Deferred()
        reactor.callLater(0, d.callback, None)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:19,代碼來源:test_threadable.py

示例6: test_enumerate_after_join

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def test_enumerate_after_join(self):
        # Try hard to trigger #1703448: a thread is still returned in
        # threading.enumerate() after it has been join()ed.
        enum = threading.enumerate
        old_interval = sys.getcheckinterval()
        sys.setcheckinterval(1)
        try:
            for i in xrange(1, 1000):
                t = threading.Thread(target=lambda: None)
                t.start()
                t.join()
                l = enum()
                self.assertFalse(t in l,
                    "#1703448 triggered after %d trials: %s" % (i, l))
        finally:
            sys.setcheckinterval(old_interval) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:18,代碼來源:test_threading.py

示例7: __init__

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def __init__(self):
        self.interval = 1/60.0
        sys.setcheckinterval(1000)
        try:
            sys.setswitchinterval(self.interval)
        except AttributeError:
            # sys.setswitchinterval is only python3
            pass

        self.taskQueue = asynctaskqueue.AsyncTaskQueue()
        self.pendingTasks = []
        self.threads = []
        self.timer = TimerCallback(callback=self._onTimer, targetFps=1/self.interval)

        # call timer.start here to initialize the QTimer now on the main thread
        self.timer.start() 
開發者ID:RobotLocomotion,項目名稱:director,代碼行數:18,代碼來源:taskrunner.py

示例8: setup_gil

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def setup_gil():
    """
    Set extremely long GIL release interval to let threads naturally progress
    through CPU-heavy sequences without forcing the wake of another thread that
    may contend trying to run the same CPU-heavy code. For the new-style
    Ansible work, this drops runtime ~33% and involuntary context switches by
    >80%, essentially making threads cooperatively scheduled.
    """
    try:
        # Python 2.
        sys.setcheckinterval(100000)
    except AttributeError:
        pass

    try:
        # Python 3.
        sys.setswitchinterval(10)
    except AttributeError:
        pass 
開發者ID:dw,項目名稱:mitogen,代碼行數:21,代碼來源:utils.py

示例9: test_setcheckinterval

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def test_setcheckinterval(self):
        self.assertRaises(TypeError, sys.setcheckinterval)
        orig = sys.getcheckinterval()
        for n in 0, 100, 120, orig: # orig last to restore starting state
            sys.setcheckinterval(n)
            self.assertEqual(sys.getcheckinterval(), n) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_sys.py

示例10: setUp

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def setUp(self):
        """
        Reduce the CPython check interval so that thread switches happen much
        more often, hopefully exercising more possible race conditions.  Also,
        delay actual test startup until the reactor has been started.
        """
        if _PY3:
            if getattr(sys, 'getswitchinterval', None) is not None:
                self.addCleanup(sys.setswitchinterval, sys.getswitchinterval())
                sys.setswitchinterval(0.0000001)
        else:
            if getattr(sys, 'getcheckinterval', None) is not None:
                self.addCleanup(sys.setcheckinterval, sys.getcheckinterval())
                sys.setcheckinterval(7) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:16,代碼來源:test_threadable.py

示例11: test_string_slicing

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def test_string_slicing(self):
        def f(ct, passCt,chars):
            x = "asdfasdf" * (ct / 8)
            res = 0
            for _ in xrange(passCt):
                for ix in xrange(len(x)):
                    res = res + len(x[ix:ix+chars])
            return res

        self.evaluateWithExecutor(f, 1000000, 1, 2)
        self.evaluateWithExecutor(f, 10000, 1, 2)

        def runTest(func, name):
            PerformanceTestReporter.PerfTest(name)(func)()

        runTest(lambda: self.evaluateWithExecutor(f, 1000000, 10, 2), "pyfora.string_slicing_10mm.2_char_large_string.pyfora")
        runTest(lambda: self.evaluateWithExecutor(f, 1000000, 10, 200), "pyfora.string_slicing_10mm.200_char_large_string.pyfora")
        runTest(lambda: self.evaluateWithExecutor(f, 10000, 1000, 2), "pyfora.string_slicing_10mm.2_char_small_string.pyfora")
        runTest(lambda: self.evaluateWithExecutor(f, 10000, 1000, 200), "pyfora.string_slicing_10mm.200_char_small_string.pyfora")

        sys.setcheckinterval(100000)

        runTest(lambda: f(1000000, 10, 2), "pyfora.string_slicing_10mm.2_char_large_string.native")
        runTest(lambda: f(1000000, 10, 200), "pyfora.string_slicing_10mm.200_char_large_string.native")
        runTest(lambda: f(10000, 1000, 2), "pyfora.string_slicing_10mm.2_char_small_string.native")
        runTest(lambda: f(10000, 1000, 200), "pyfora.string_slicing_10mm.200_char_small_string.native")

        sys.setcheckinterval(100) 
開發者ID:ufora,項目名稱:ufora,代碼行數:30,代碼來源:StringTestCases.py

示例12: test_string_slicing_into_vector

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def test_string_slicing_into_vector(self):
        def testFunction(ct, passCt,chars):
            x = "asdfasdf" * (ct / 8)
            res = 0
            for _ in xrange(passCt):
                v = [x[ix*chars:ix*chars+chars] for ix in xrange(len(x) / chars)]
                for e in v:
                    res = res + len(e)
            return res
        f = testFunction

        self.evaluateWithExecutor(f, 1000000, 1, 2)
        self.evaluateWithExecutor(f, 10000, 1, 2)

        def runTest(func, name):
            PerformanceTestReporter.PerfTest(name)(func)()

        runTest(lambda: self.evaluateWithExecutor(f, 1000000, 10, 2), "pyfora.string_slicing_into_vector_10mm.2_char_large_string.pyfora")
        runTest(lambda: self.evaluateWithExecutor(f, 1000000, 1000, 200), "pyfora.string_slicing_into_vector_10mm.200_char_large_string.pyfora")
        runTest(lambda: self.evaluateWithExecutor(f, 10000, 1000, 2), "pyfora.string_slicing_into_vector_10mm.2_char_small_string.pyfora")
        runTest(lambda: self.evaluateWithExecutor(f, 10000, 100000, 200), "pyfora.string_slicing_into_vector_10mm.200_char_small_string.pyfora")

        sys.setcheckinterval(100000)

        runTest(lambda: f(1000000, 10, 2), "pyfora.string_slicing_into_vector_10mm.2_char_large_string.native")
        runTest(lambda: f(1000000, 1000, 200), "pyfora.string_slicing_into_vector_10mm.200_char_large_string.native")
        runTest(lambda: f(10000, 1000, 2), "pyfora.string_slicing_into_vector_10mm.2_char_small_string.native")
        runTest(lambda: f(10000, 100000, 200), "pyfora.string_slicing_into_vector_10mm.200_char_small_string.native")

        sys.setcheckinterval(100) 
開發者ID:ufora,項目名稱:ufora,代碼行數:32,代碼來源:StringTestCases.py

示例13: test_setcheckinterval

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def test_setcheckinterval(self):
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            self.assertRaises(TypeError, sys.setcheckinterval)
            orig = sys.getcheckinterval()
            for n in 0, 100, 120, orig: # orig last to restore starting state
                sys.setcheckinterval(n)
                self.assertEqual(sys.getcheckinterval(), n) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:10,代碼來源:test_sys.py

示例14: test_setcheckinterval

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def test_setcheckinterval(self):
        self.assertRaises(TypeError, sys.setcheckinterval)
        orig = sys.getcheckinterval()
        for n in 0, 100, 120, orig: # orig last to restore starting state
            sys.setcheckinterval(n)
            self.assertEquals(sys.getcheckinterval(), n) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:8,代碼來源:test_sys.py

示例15: setUpClass

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import setcheckinterval [as 別名]
def setUpClass(self):
            self.checkInterval = sys.getcheckinterval()
            sys.setcheckinterval(7) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:5,代碼來源:test_threadable.py


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