def main(src_program, src_function, dst_program, f_silent, f_image, f_overwrite, f_top):
sys.setrecursionlimit(3000)
start_time = time.time()
search_results = search_function(src_function, src_program, dst_program, f_top)
if not search_results: return False
else:
(results, stats) = search_results
result_time = time.time() - start_time
stats["time"] = result_time
if not f_silent:
print_results(results, stats, src_program, src_function, dst_program)
"""
if f_image:
def image_dump(program, function, f_overwrite):
function_short = get_short_function_name(function)
if not f_overwrite:
if os.path.exists(os.path.join(get_dump_png_path(program), function_short + ".png")):
return
flag = ["-o"] if f_overwrite else []
cmd = ["python", "idascript.py", program, "bingrep_dump2.py", "-f", function, "-i"] + flag
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.communicate()
print "Top 10 function images were dumped."
"""
return (results, stats)
python类setrecursionlimit()的实例源码
def main(function, f_image, f_all, f_overwrite):
sys.setrecursionlimit(3000)
program = idaapi.get_root_filename()
start_time = time.time()
cfgs = get_cfgs()
dump_function_info(cfgs, program, function, f_image, f_all, f_overwrite)
result_time = time.time() - start_time
print "Dump finished."
print "result_time: " + str(result_time) + " sec."
def __copy_theano(self, theano_f):
sys.setrecursionlimit(5000)
pickle.dump(theano_f,
open('/tmp/theano_model.p', 'wb'),
protocol=pickle.HIGHEST_PROTOCOL)
copied_f = pickle.load(open('/tmp/theano_model.p', 'rb'))
sys.setrecursionlimit(1000)
return copied_f
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())
def main():
sys.setrecursionlimit(N * N + 10)
for i in range(N):
visited.append([False] * N)
maze.append([0] * N)
depth_first_search(0, 0, 0)
with open('maze_gen.out', 'w') as f:
for row in maze:
f.write(' '.join(map(str, row)))
f.write('\n')
def serialize(self, file_name):
"""
Serialize this HMM to a file.
@param file_name: target file name
@type file_name: str
"""
rec = sys.getrecursionlimit()
sys.setrecursionlimit(10000)
csb.io.Pickle.dump(self, open(file_name, 'wb'))
sys.setrecursionlimit(rec)
def deserialize(file_name):
"""
De-serialize an HMM from a file.
@param file_name: source file name (pickle)
@type file_name: str
"""
rec = sys.getrecursionlimit()
sys.setrecursionlimit(10000)
try:
return csb.io.Pickle.load(open(file_name, 'rb'))
finally:
sys.setrecursionlimit(rec)
def save_model(model, file=None):
"""
Save the model to file with cPickle
This function is used by the training function to save the model.
Parameters
----------
model : :class:`yadll.model.Model`
model to be saved in file
file : `string`
file name
"""
if file is None:
if model.file is None:
logger.error('No file name. Model not saved.')
return
else:
d_file = model.file
else:
d_file = file
try:
with open(d_file, 'wb') as f:
pickle.dump(model, f, pickle.HIGHEST_PROTOCOL)
except RuntimeError:
sys.setrecursionlimit(5000)
with open(d_file, 'wb') as f:
pickle.dump(model, f, pickle.HIGHEST_PROTOCOL)
def limited_recursion(recursion_limit):
"""
Prevent unlimited recursion.
"""
old_limit = sys.getrecursionlimit()
sys.setrecursionlimit(recursion_limit)
try:
yield
finally:
sys.setrecursionlimit(old_limit)
def set_recursion_limit(n=1 * 10 ** 8):
sys.setrecursionlimit(n)
return True
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)
def solve(self):
# increase recursion depth to avoid
sys.setrecursionlimit(10000)
for server in self.servers:
logging.info("Server number " + str(server.id))
self.knapsack_list = [ChoiceStructure(video, server) for video in self.videos]
self.knapsack_iterative()
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)
def opt_recursionlimit(self, arg):
"""see sys.setrecursionlimit()"""
try:
sys.setrecursionlimit(int(arg))
except (TypeError, ValueError):
raise usage.UsageError(
"argument to recursionlimit must be an integer")
def setup_tests():
sys.setrecursionlimit(2000)
directory = os.path.dirname(__file__)
xml_idioms_dir = find_dir(directory, "idioms-xml")
json_idioms_dir = find_dir(directory, "idioms-json")
print("Setting up tests from following directories...")
print(xml_idioms_dir)
print(json_idioms_dir)
for json_filename in sorted(os.listdir(json_idioms_dir)):
if json_filename.endswith(".json"):
path = os.path.join(json_idioms_dir, json_filename)
json_file = open(path, "r")
io = StringIO(json_file.read())
loaded_json = json.load(io)
json_file.close()
MASTER_JSON_FILES.append(loaded_json)
for xml_filename in sorted(os.listdir(xml_idioms_dir)):
if xml_filename.endswith(".xml"):
path = os.path.join(xml_idioms_dir, xml_filename)
XML_FILENAMES.append(xml_filename.split(".")[0])
TESTED_XML_FILES.append(path)
def main():
sys.setrecursionlimit(100000)
#take_data( quick_sort_helper , "quick_sort-ordered.csv" , generate_ordered_vector )
#take_data( quick_sort_helper , "quick_sort-unordered.csv" , generate_inverse_vector )
take_data( quick_sort_helper , "quick_sort-mixed.csv" , generate_vector )
#take_data( merge_sort_helper , "merge_sort-mixed.csv" , generate_vector )
#take_data( merge_sort_helper , "merge_sort-ordered.csv" , generate_ordered_vector )
#take_data( merge_sort_helper , "merge_sort-unordered.csv" , generate_inverse_vector )
#take_data( insertion_sort , "insertion_sort-mixed.csv" , generate_vector )
#take_data( insertion_sort , "insertion_sort-ordered.csv" , generate_ordered_vector )
#take_data( insertion_sort , "insertion_sort-unordered.csv" , generate_inverse_vector )
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())
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)
driver_unit_test.py 文件源码
项目:cloudsdk-test-driver
作者: GoogleCloudPlatform
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def setUpClass(cls):
# If there's an infinite recursion in the dictionary code, this will help
# make the error messages more readable.
cls._old_limit = sys.getrecursionlimit()
sys.setrecursionlimit(100)
driver_unit_test.py 文件源码
项目:cloudsdk-test-driver
作者: GoogleCloudPlatform
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def tearDownClass(cls):
# Put the recursion limit back where it was.
sys.setrecursionlimit(cls._old_limit)