当前位置: 首页>>代码示例>>Python>>正文


Python sys.getrecursionlimit方法代码示例

本文整理汇总了Python中sys.getrecursionlimit方法的典型用法代码示例。如果您正苦于以下问题:Python sys.getrecursionlimit方法的具体用法?Python sys.getrecursionlimit怎么用?Python sys.getrecursionlimit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sys的用法示例。


在下文中一共展示了sys.getrecursionlimit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: worker_loop

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def worker_loop(dataset, key_queue, data_queue, batchify_fn):
    """Worker loop for multiprocessing DataLoader."""
    # re-fork a new recordio handler in new process if applicable
    # for a dataset with transform function, the depth of MXRecordIO is 1
    # for a lazy transformer, the depth is 2
    # for a user defined transformer, the depth is unknown, try a reasonable depth
    limit = sys.getrecursionlimit()
    max_recursion_depth = min(limit - 5, max(10, limit // 2))
    _recursive_fork_recordio(dataset, 0, max_recursion_depth)

    while True:
        idx, samples = key_queue.get()
        if idx is None:
            break
        batch = batchify_fn([dataset[i] for i in samples])
        data_queue.put((idx, batch)) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:18,代码来源:dataloader.py

示例2: pickle_model

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def pickle_model(
        path, 
        model, 
        word2index_x,
        word2index_y,
        index2word_x,
        index2word_y):
    import sys
    import cPickle as pickle
    modifier=10
    tmp = sys.getrecursionlimit()
    sys.setrecursionlimit(tmp*modifier)
    with open(path, 'wb') as f:
        p_dict = {'model':model,
                'word2index_x':word2index_x,
                'word2index_y':word2index_y,
                'index2word_x':index2word_x,
                'index2word_y':index2word_y}
        pickle.dump(p_dict, f, protocol=2)
    sys.setrecursionlimit(tmp) 
开发者ID:mateuszmalinowski,项目名称:visual_turing_test-tutorial,代码行数:22,代码来源:read_write.py

示例3: run_test_for_event

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def run_test_for_event(self, event):
        """Tests that an exception raised in response to the given event is
        handled OK."""
        self.raiseOnEvent = event
        try:
            for i in xrange(sys.getrecursionlimit() + 1):
                sys.settrace(self.trace)
                try:
                    self.f()
                except ValueError:
                    pass
                else:
                    self.fail("exception not raised!")
        except RuntimeError:
            self.fail("recursion counter not reset")

    # Test the handling of exceptions raised by each kind of trace event. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_sys_settrace.py

示例4: test_recursionlimit

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def test_recursionlimit(self):
        self.assertRaises(TypeError, sys.getrecursionlimit, 42)
        oldlimit = sys.getrecursionlimit()
        self.assertRaises(TypeError, sys.setrecursionlimit)
        self.assertRaises(ValueError, sys.setrecursionlimit, -42)
        sys.setrecursionlimit(10000)
        self.assertEqual(sys.getrecursionlimit(), 10000)
        sys.setrecursionlimit(oldlimit)

        self.assertRaises(OverflowError, sys.setrecursionlimit, 1 << 31)
        try:
            sys.setrecursionlimit((1 << 31) - 5)
            try:
                # issue13546: isinstance(e, ValueError) used to fail
                # when the recursion limit is close to 1<<31
                raise ValueError()
            except ValueError, e:
                pass
        finally:
            sys.setrecursionlimit(oldlimit) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_sys.py

示例5: test_isinstance_recursion

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def test_isinstance_recursion(self):
        reclimit = sys.getrecursionlimit()
        if reclimit == sys.maxint:
            sys.setrecursionlimit(1001)

        # Make sure that calling isinstance with a deeply nested tuple for its
        # argument will raise RuntimeError eventually.
        def blowstack(fxn, arg, compare_to):
            tuple_arg = (compare_to,)
            for cnt in xrange(sys.getrecursionlimit()+5):
                tuple_arg = (tuple_arg,)
                fxn(arg, tuple_arg)
        
        self.assertRaises(RuntimeError, blowstack, isinstance, '', str)

        sys.setrecursionlimit(reclimit) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_class.py

示例6: test_repr

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def test_repr(self):
        l0 = []
        l2 = [0, 1, 2]
        a0 = self.type2test(l0)
        a2 = self.type2test(l2)

        self.assertEqual(str(a0), str(l0))
        self.assertEqual(repr(a0), repr(l0))
        self.assertEqual(repr(a2), repr(l2))
        self.assertEqual(str(a2), "[0, 1, 2]")
        self.assertEqual(repr(a2), "[0, 1, 2]")

        a2.append(a2)
        a2.append(3)
        self.assertEqual(str(a2), "[0, 1, 2, [...], 3]")
        self.assertEqual(repr(a2), "[0, 1, 2, [...], 3]")

        l0 = []
        for i in xrange(sys.getrecursionlimit() + 100):
            l0 = [l0]
        self.assertRaises(RuntimeError, repr, l0) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:23,代码来源:list_tests.py

示例7: test_getWorkerArguments

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def test_getWorkerArguments(self):
        """
        C{_getWorkerArguments} discards options like C{random} as they only
        matter in the manager, and forwards options like C{recursionlimit} or
        C{disablegc}.
        """
        self.addCleanup(sys.setrecursionlimit, sys.getrecursionlimit())
        if gc.isenabled():
            self.addCleanup(gc.enable)

        self.options.parseOptions(["--recursionlimit", "2000", "--random",
                                   "4", "--disablegc"])
        args = self.options._getWorkerArguments()
        self.assertIn("--disablegc", args)
        args.remove("--disablegc")
        self.assertEqual(["--recursionlimit", "2000"], args) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_script.py

示例8: test_tco_too_many_frames

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def test_tco_too_many_frames(self):
        frames = sys.getrecursionlimit()

        def f(n):
            if not n:
                return None
            return f(n - 1)

        # Make sure this is actually too many frames.
        with self.assertRaises(RuntimeError):
            f(frames)

        @tco
        def g(n):
            if not n:
                return None
            return g.tailcall(n - 1)

        # Show that the tco version can handle the same number of frames.
        self.assertIsNone(g(frames)) 
开发者ID:quantopian,项目名称:qdb,代码行数:22,代码来源:test_misc.py

示例9: test_why_are_you_executing_all_these_commands

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def test_why_are_you_executing_all_these_commands(self):
        db = Qdb(
            uuid='send_stack_test',
            cmd_manager=self.cmd_manager,
            host=self.tracer_host,
            port=self.tracer_port,
            redirect_output=False,
            green=True,
        )
        gyield()
        for n in range(sys.getrecursionlimit()):
            self.server.session_store.send_to_tracer(
                uuid=db.uuid,
                event=fmt_msg('eval', 'None')
            )
        self.server.session_store.send_to_tracer(
            uuid=db.uuid,
            event=fmt_msg('continue')
        )
        with gevent.Timeout(1):
            db.set_trace(stop=True) 
开发者ID:quantopian,项目名称:qdb,代码行数:23,代码来源:test_cmd_manager.py

示例10: run_test_for_event

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def run_test_for_event(self, event):
        """Tests that an exception raised in response to the given event is
        handled OK."""
        self.raiseOnEvent = event
        try:
            for i in range(sys.getrecursionlimit() + 1):
                sys.settrace(self.trace)
                try:
                    self.f()
                except ValueError:
                    pass
                else:
                    self.fail("exception not raised!")
        except RuntimeError:
            self.fail("recursion counter not reset")

    # Test the handling of exceptions raised by each kind of trace event. 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_sys_settrace.py

示例11: test_repr

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def test_repr(self):
        l0 = []
        l2 = [0, 1, 2]
        a0 = self.type2test(l0)
        a2 = self.type2test(l2)

        self.assertEqual(str(a0), str(l0))
        self.assertEqual(repr(a0), repr(l0))
        self.assertEqual(repr(a2), repr(l2))
        self.assertEqual(str(a2), "[0, 1, 2]")
        self.assertEqual(repr(a2), "[0, 1, 2]")

        a2.append(a2)
        a2.append(3)
        self.assertEqual(str(a2), "[0, 1, 2, [...], 3]")
        self.assertEqual(repr(a2), "[0, 1, 2, [...], 3]")

        l0 = []
        for i in range(sys.getrecursionlimit() + 100):
            l0 = [l0]
        self.assertRaises(RecursionError, repr, l0) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:list_tests.py

示例12: test_compiler_recursion_limit

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def test_compiler_recursion_limit(self):
        # Expected limit is sys.getrecursionlimit() * the scaling factor
        # in symtable.c (currently 3)
        # We expect to fail *at* that limit, because we use up some of
        # the stack depth limit in the test suite code
        # So we check the expected limit and 75% of that
        # XXX (ncoghlan): duplicating the scaling factor here is a little
        # ugly. Perhaps it should be exposed somewhere...
        fail_depth = sys.getrecursionlimit() * 3
        success_depth = int(fail_depth * 0.75)

        def check_limit(prefix, repeated):
            expect_ok = prefix + repeated * success_depth
            self.compile_single(expect_ok)
            broken = prefix + repeated * fail_depth
            details = "Compiling ({!r} + {!r} * {})".format(
                         prefix, repeated, fail_depth)
            with self.assertRaises(RecursionError, msg=details):
                self.compile_single(broken)

        check_limit("a", "()")
        check_limit("a", ".b")
        check_limit("a", "[0]")
        check_limit("a", "*a") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_compile.py

示例13: _objs_opts

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def _objs_opts(objs, all=None, **opts):
    '''Return given or 'all' objects
       and the remaining options.
    '''
    if objs:  # given objects
        t = objs
    elif all in (False, None):
        t = ()
    elif all is True:  # 'all' objects ...
         # ... modules first, globals and stack
         # (may contain duplicate objects)
        t = tuple(_values(sys.modules)) + (
            globals(), stack(sys.getrecursionlimit())[2:])
    else:
        raise ValueError('invalid option: %s=%r' % ('all', all))
    return t, opts  #PYCHOK OK 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:18,代码来源:asizeof.py

示例14: test_recursionlimit_recovery

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def test_recursionlimit_recovery(self):
        if hasattr(sys, 'gettrace') and sys.gettrace():
            self.skipTest('fatal error if run with a trace function')

        # NOTE: this test is slightly fragile in that it depends on the current
        # recursion count when executing the test being low enough so as to
        # trigger the recursion recovery detection in the _Py_MakeEndRecCheck
        # macro (see ceval.h).
        oldlimit = sys.getrecursionlimit()
        def f():
            f()
        try:
            for i in (50, 1000):
                # Issue #5392: stack overflow after hitting recursion limit twice
                sys.setrecursionlimit(i)
                self.assertRaises(RuntimeError, f)
                self.assertRaises(RuntimeError, f)
        finally:
            sys.setrecursionlimit(oldlimit) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:21,代码来源:test_sys.py

示例15: test_repr

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getrecursionlimit [as 别名]
def test_repr(self):
        l0 = []
        l2 = [0, 1, 2]
        a0 = self.type2test(l0)
        a2 = self.type2test(l2)

        self.assertEqual(str(a0), str(l0))
        self.assertEqual(repr(a0), repr(l0))
        self.assertEqual(repr(a2), repr(l2))
        self.assertEqual(str(a2), "[0, 1, 2]")
        self.assertEqual(repr(a2), "[0, 1, 2]")

        a2.append(a2)
        a2.append(3)
        self.assertEqual(str(a2), "[0, 1, 2, [...], 3]")
        self.assertEqual(repr(a2), "[0, 1, 2, [...], 3]")

        l0 = []
        for i in range(sys.getrecursionlimit() + 100):
            l0 = [l0]
        self.assertRaises(RuntimeError, repr, l0) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:23,代码来源:list_tests.py


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