本文整理匯總了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))
示例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)
示例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.
示例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)
示例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)
示例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)
示例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)
示例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))
示例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)
示例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.
示例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)
示例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")
示例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
示例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)
示例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)