Python sys.setrecursionlimit() Examples
The following are 30
code examples of sys.setrecursionlimit().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sys
, or try the search function
.
Example #1
Source File: test_sys.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_recursionlimit_recovery(self): if hasattr(sys, 'gettrace') and sys.gettrace(): self.skipTest('fatal error if run with a trace function') oldlimit = sys.getrecursionlimit() def f(): f() try: for depth in (10, 25, 50, 75, 100, 250, 1000): try: sys.setrecursionlimit(depth) except RecursionError: # Issue #25274: The recursion limit is too low at the # current recursion depth continue # Issue #5392: test stack overflow after hitting recursion # limit twice self.assertRaises(RecursionError, f) self.assertRaises(RecursionError, f) finally: sys.setrecursionlimit(oldlimit)
Example #2
Source File: didyoumean_sugg_tests.py From DidYouMean-Python with MIT License | 6 votes |
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)
Example #3
Source File: didyoumean_sugg_tests.py From DidYouMean-Python with MIT License | 6 votes |
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)
Example #4
Source File: read_write.py From visual_turing_test-tutorial with MIT License | 6 votes |
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)
Example #5
Source File: parameterized_tests.py From paramz with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #6
Source File: test_sys.py From ironpython2 with Apache License 2.0 | 6 votes |
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)
Example #7
Source File: test_class.py From ironpython2 with Apache License 2.0 | 6 votes |
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)
Example #8
Source File: dependency.py From slpkg with GNU General Public License v3.0 | 6 votes |
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 []
Example #9
Source File: pickletools.py From procedural_city_generation with Mozilla Public License 2.0 | 6 votes |
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)
Example #10
Source File: test_script.py From learn_python3_spider with MIT License | 6 votes |
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)
Example #11
Source File: test_sys.py From BinderFilter with MIT License | 6 votes |
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)
Example #12
Source File: test_e2e.py From m2cgen with MIT License | 6 votes |
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()
Example #13
Source File: test_sys.py From oss-ftp with MIT License | 6 votes |
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)
Example #14
Source File: test_sys.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_recursionlimit_fatalerror(self): # A fatal error occurs if a second recursion limit is hit when recovering # from a first one. code = textwrap.dedent(""" import sys def f(): try: f() except RecursionError: f() sys.setrecursionlimit(%d) f()""") with test.support.SuppressCrashReport(): for i in (50, 1000): sub = subprocess.Popen([sys.executable, '-c', code % i], stderr=subprocess.PIPE) err = sub.communicate()[1] self.assertTrue(sub.returncode, sub.returncode) self.assertIn( b"Fatal Python error: Cannot recover from stack overflow", err)
Example #15
Source File: find_recursionlimit.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 (RecursionError, AttributeError): pass else: print("Yikes!")
Example #16
Source File: extensions.py From Diffusion-Probabilistic-Models with MIT License | 6 votes |
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)
Example #17
Source File: baseoperator.py From airflow with Apache License 2.0 | 6 votes |
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
Example #18
Source File: test_script.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)
Example #19
Source File: update_cache_compatibility.py From gated-graph-transformer-network with MIT License | 6 votes |
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)
Example #20
Source File: cli.py From m2cgen with MIT License | 6 votes |
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)
Example #21
Source File: find_recursionlimit.py From oss-ftp with MIT License | 6 votes |
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!"
Example #22
Source File: test_excinfo.py From pytest with MIT License | 5 votes |
def limited_recursion_depth(): before = sys.getrecursionlimit() sys.setrecursionlimit(150) yield sys.setrecursionlimit(before)
Example #23
Source File: test_excel.py From koala with GNU General Public License v3.0 | 5 votes |
def setUp(self): self.sp = Spreadsheet("./tests/files/NamedRanges.xlsx", ignore_sheets = ['IHS']) sys.setrecursionlimit(10000)
Example #24
Source File: test_portfolio.py From pysmt with Apache License 2.0 | 5 votes |
def test_smtlib_multi_msat(self): from pysmt.test.smtlib.parser_utils import SMTLIB_TEST_FILES, SMTLIB_DIR # On some platforms (Windows x64) the internal pickling process requires # quite a lot of recursion... old_recursion_limit = sys.getrecursionlimit() sys.setrecursionlimit(999999) for (logic, f, expected_result) in SMTLIB_TEST_FILES: smtfile = os.path.join(SMTLIB_DIR, f) if logic <= QF_UFLIRA: env = reset_env() formula = get_formula_fname(smtfile, env) # Simplifying the formula to reduce its depth to avoid errors on some # platforms until issue #455 for details. formula = formula.simplify() with Portfolio([("msat", {"random_seed": 1}), ("msat", {"random_seed": 17}), ("msat", {"random_seed": 42})], logic=logic, environment=env, incremental=False, generate_models=False) as s: res = s.is_sat(formula) self.assertEqual(expected_result, res, smtfile) #reset recursion limit sys.setrecursionlimit(old_recursion_limit)
Example #25
Source File: extensions.py From Diffusion-Probabilistic-Models with MIT License | 5 votes |
def do(self, callback_name, *args): import sys sys.setrecursionlimit(10000000) print "plotting parameters" for param in self.blocks_model.parameters: param_name = param.name filename_safe_name = '-'.join(param_name.split('/')[2:]).replace(' ', '_') base_fname_part1 = self.path + '/params-' + filename_safe_name base_fname_part2 = '_batch%06d'%self.main_loop.status['iterations_done'] viz.plot_parameter(param.get_value(), base_fname_part1, base_fname_part2, title=param_name, n_colors=self.model.n_colors)
Example #26
Source File: testmock.py From jawfish with MIT License | 5 votes |
def test_copy(self): current = sys.getrecursionlimit() self.addCleanup(sys.setrecursionlimit, current) # can't use sys.maxint as this doesn't exist in Python 3 sys.setrecursionlimit(int(10e8)) # this segfaults without the fix in place copy.copy(Mock())
Example #27
Source File: testmock.py From Imogen with MIT License | 5 votes |
def test_copy(self): current = sys.getrecursionlimit() self.addCleanup(sys.setrecursionlimit, current) # can't use sys.maxint as this doesn't exist in Python 3 sys.setrecursionlimit(int(10e8)) # this segfaults without the fix in place copy.copy(Mock())
Example #28
Source File: util.py From coconut with Apache License 2.0 | 5 votes |
def __call__(self, *args, **kwargs): """Set up new process then calls the method.""" sys.setrecursionlimit(self.recursion) logger.copy_from(self.logger) return getattr(self.base, self.method)(*args, **kwargs)
Example #29
Source File: pdfcropper.py From krop with GNU General Public License v3.0 | 5 votes |
def writeToStream(self, stream): # For certain large pdf files, PdfFileWriter.write() causes the error: # maximum recursion depth exceeded while calling a Python object # This issue is present in pyPdf as well as PyPDF2 1.23 # We therefore temporarily increase the recursion limit. old_reclimit = sys.getrecursionlimit() sys.setrecursionlimit(10000) self.output.write(stream) sys.setrecursionlimit(old_reclimit)
Example #30
Source File: util.py From document-image-binarization with GNU General Public License v3.0 | 5 votes |
def init(): random.seed(1337) np.set_printoptions(threshold=sys.maxsize) np.random.seed(1337) sys.setrecursionlimit(40000) # ----------------------------------------------------------------------------