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


Python sys.setrecursionlimit方法代码示例

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


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

示例1: main

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [as 别名]
def main(cache_dir):
    files_list = list(os.listdir(cache_dir))
    for file in files_list:
        full_filename = os.path.join(cache_dir, file)
        if os.path.isfile(full_filename):
            print("Processing {}".format(full_filename))
            m, stored_kwargs = pickle.load(open(full_filename, 'rb'))
            updated_kwargs = util.get_compatible_kwargs(model.Model, stored_kwargs)

            model_hash = util.object_hash(updated_kwargs)
            print("New hash -> " + model_hash)
            model_filename = os.path.join(cache_dir, "model_{}.p".format(model_hash))
            sys.setrecursionlimit(100000)
            pickle.dump((m,updated_kwargs), open(model_filename,'wb'), protocol=pickle.HIGHEST_PROTOCOL)

            os.remove(full_filename) 
开发者ID:hexahedria,项目名称:gated-graph-transformer-network,代码行数:18,代码来源:update_cache_compatibility.py

示例2: pickle_model

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [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: test_unqualified_exec

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [as 别名]
def test_unqualified_exec(self):
        """Exec in nested functions."""
        # NICE_TO_HAVE
        before, after = before_and_after((3, 0))
        codes = [
            func_gen(
                'func1',
                body="bar='1'\n" + func_gen(
                    'func2',
                    body="exec(bar)",
                    args=''),
                args=''),
            func_gen(
                'func1',
                body="exec('1')\n" + func_gen('func2', body='True')),
        ]
        sys.setrecursionlimit(1000)  # needed for weird PyPy versions
        for code in codes:
            self.throws(code, UNQUALIFIED_EXEC, [], before)
            self.runs(code, after)
        sys.setrecursionlimit(initial_recursion_limit) 
开发者ID:SylvainDe,项目名称:DidYouMean-Python,代码行数:23,代码来源:didyoumean_sugg_tests.py

示例4: test_import_star

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [as 别名]
def test_import_star(self):
        """'import *' in nested functions."""
        # NICE_TO_HAVE
        codes = [
            func_gen(
                'func1',
                body=func_gen('func2', body='from math import *\nTrue')),
            func_gen(
                'func1',
                body='from math import *\n' + func_gen('func2', body='True')),
        ]
        sys.setrecursionlimit(1000)  # needed for weird PyPy versions
        with warnings.catch_warnings():
            warnings.simplefilter("ignore", category=SyntaxWarning)
            for code in codes:
                self.throws(code, IMPORTSTAR)
        sys.setrecursionlimit(initial_recursion_limit) 
开发者ID:SylvainDe,项目名称:DidYouMean-Python,代码行数:19,代码来源:didyoumean_sugg_tests.py

示例5: test_recursion_limit

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [as 别名]
def test_recursion_limit(self):
        # Recursion limit reached for unnamed kernels:
        def max_recursion():
            kerns = [P('rbf', lengthscale=Param('lengthscale', 1), variance=Param('variance', 1)) for i in range(20)]
            p = Parameterized('add')
            p.link_parameters(*kerns)
        import sys
        sys.setrecursionlimit(100)
        try:
            from builtins import RecursionError as RE
        except:
            RE = RuntimeError
        self.assertRaisesRegexp(RE, "aximum recursion depth", max_recursion)
        # Recursion limit not reached if kernels are named individually:
        sys.setrecursionlimit(1000)
        p = Parameterized('add')
        kerns = [P('rbf_{}'.format(i), lengthscale=Param('lengthscale', 1), variance=Param('variance', 1)) for i in range(10)]
        p.link_parameters(*kerns) 
开发者ID:sods,项目名称:paramz,代码行数:20,代码来源:parameterized_tests.py

示例6: test_recursionlimit

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [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

示例7: test_isinstance_recursion

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [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

示例8: sbo

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [as 别名]
def sbo(self, name):
        """Build all dependencies of a package
        """
        if (self.meta.rsl_deps in ["on", "ON"] and
                "--resolve-off" not in self.flag):
            sys.setrecursionlimit(10000)
            dependencies = []
            requires = SBoGrep(name).requires()
            if requires:
                for req in requires:
                    # avoid to add %README% as dependency and
                    # if require in blacklist
                    if "%README%" not in req and req not in self.blacklist:
                        dependencies.append(req)
                self.deep_check(dependencies)
            return self.dep_results
        else:
            return [] 
开发者ID:dslackw,项目名称:slpkg,代码行数:20,代码来源:dependency.py

示例9: reconstruct

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [as 别名]
def reconstruct(path):
    try:
        import os
        import procedural_city_generation
        fullpath = os.path.dirname(procedural_city_generation.__file__) + "/temp/" + path

        import pickle
        with open(fullpath, 'rb') as f:
            vertex_list = pickle.loads(f.read())
            for i, v in enumerate(vertex_list):
                v.selfindex = i
            return vertex_list

        print("Input could not be located. Try to run the previous program in the chain first.")
        return 0
    except:
        print("Recursionlimit was not enough - Pickle trying again with sys.recusionlimit at 50000")
        import sys
        sys.setrecursionlimit(50000)
        reconstruct(path) 
开发者ID:josauder,项目名称:procedural_city_generation,代码行数:22,代码来源:pickletools.py

示例10: check_limit

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [as 别名]
def check_limit(n, test_func_name):
    sys.setrecursionlimit(n)
    if test_func_name.startswith("test_"):
        print test_func_name[5:]
    else:
        print test_func_name
    test_func = globals()[test_func_name]
    try:
        test_func()
    # AttributeError can be raised because of the way e.g. PyDict_GetItem()
    # silences all exceptions and returns NULL, which is usually interpreted
    # as "missing attribute".
    except (RuntimeError, AttributeError):
        pass
    else:
        print "Yikes!" 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:18,代码来源:find_recursionlimit.py

示例11: test_e2e

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [as 别名]
def test_e2e(estimator, executor_cls, model_trainer,
             is_fast, global_tmp_dir):
    sys.setrecursionlimit(RECURSION_LIMIT)

    X_test, y_pred_true, fitted_estimator = model_trainer(estimator)
    executor = executor_cls(fitted_estimator)

    idxs_to_test = [0] if is_fast else range(len(X_test))

    executor.prepare_global(global_tmp_dir=global_tmp_dir)
    with executor.prepare_then_cleanup():
        for idx in idxs_to_test:
            y_pred_executed = executor.predict(X_test[idx])
            print(f"expected={y_pred_true[idx]}, actual={y_pred_executed}")
            res = np.isclose(y_pred_true[idx], y_pred_executed, atol=ATOL)
            assert res if isinstance(res, bool) else res.all() 
开发者ID:BayesWitnesses,项目名称:m2cgen,代码行数:18,代码来源:test_e2e.py

示例12: generate_code

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [as 别名]
def generate_code(args):
    sys.setrecursionlimit(args.recursion_limit)

    with args.infile as f:
        model = pickle.load(f)

    exporter, supported_args = LANGUAGE_TO_EXPORTER[args.language]

    kwargs = {}
    for arg_name in supported_args:
        arg_value = getattr(args, arg_name)
        if arg_value is not None:
            kwargs[arg_name] = arg_value

        # Special handling for the function_name parameter, which needs to be
        # the same as the default value of the keyword argument of the exporter
        # (this is due to languages like C# which prefer their method names to
        # follow PascalCase unlike all the other supported languages -- see
        # https://github.com/BayesWitnesses/m2cgen/pull/166#discussion_r379867601
        # for more).
        if arg_name == 'function_name' and arg_value is None:
            param = inspect.signature(exporter).parameters['function_name']
            kwargs[arg_name] = param.default

    return exporter(model, **kwargs) 
开发者ID:BayesWitnesses,项目名称:m2cgen,代码行数:27,代码来源:cli.py

示例13: test_getWorkerArguments

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [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

示例14: __deepcopy__

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [as 别名]
def __deepcopy__(self, memo):
        """
        Hack sorting double chained task lists by task_id to avoid hitting
        max_depth on deepcopy operations.
        """
        sys.setrecursionlimit(5000)  # TODO fix this in a better way
        cls = self.__class__
        result = cls.__new__(cls)
        memo[id(self)] = result

        # noinspection PyProtectedMember
        shallow_copy = cls.shallow_copy_attrs + \
            cls._base_operator_shallow_copy_attrs  # pylint: disable=protected-access

        for k, v in self.__dict__.items():
            if k not in shallow_copy:
                # noinspection PyArgumentList
                setattr(result, k, copy.deepcopy(v, memo))
            else:
                setattr(result, k, copy.copy(v))
        return result 
开发者ID:apache,项目名称:airflow,代码行数:23,代码来源:baseoperator.py

示例15: do

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setrecursionlimit [as 别名]
def do(self, callback_name, *args):

        import sys
        sys.setrecursionlimit(10000000)

        print "generating samples"
        base_fname_part1 = self.path + '/samples-'
        base_fname_part2 = '_batch%06d'%self.main_loop.status['iterations_done']
        sampler.generate_samples(self.model, self.get_mu_sigma,
            n_samples=self.n_samples, inpaint=False, denoise_sigma=None, X_true=None,
            base_fname_part1=base_fname_part1, base_fname_part2=base_fname_part2)
        sampler.generate_samples(self.model, self.get_mu_sigma,
            n_samples=self.n_samples, inpaint=True, denoise_sigma=None, X_true=self.X,
            base_fname_part1=base_fname_part1, base_fname_part2=base_fname_part2)
        sampler.generate_samples(self.model, self.get_mu_sigma,
            n_samples=self.n_samples, inpaint=False, denoise_sigma=1, X_true=self.X,
            base_fname_part1=base_fname_part1, base_fname_part2=base_fname_part2) 
开发者ID:Sohl-Dickstein,项目名称:Diffusion-Probabilistic-Models,代码行数:19,代码来源:extensions.py


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