There is a function in my code (which gets executed in typically 1-2 seconds). For a particular set of arguments, I see that the python gets hung and eventually after few hours the kernel gets killed. For whatever reason (not figured out yet), the same parameter set executes the function just fine. So my question is: Is there a way to control the amount of time assigned to execute a particular line of code? If it exceeds the time assigned to that particular line, can we a) Re-run the code automatically or b) Go back few steps to re-execute that line or c) Skip the execution of that line
EDIT: This code catches runtime error for some iteration (number of iteration is not fixed) but then gets hung. I need to skip the following line: obj = package.class0(key='Key0', **p, _verbose=0) This is causing kernel getting hung
import package
par = [1.294505562707576551e+01, 6.965364410093530800e-01, 5.707082620814450280e+00,
2.537535861030653095e+00,
1.670415320843951779e-01, -1.528978502298340203e+01, 2.379290972641865665e+02,
3.085337613758109665e+00,
3.420212454861922424e+01,
2.943414981550797904e+01,
2.059940694387249849e+01,
-1.147125847273145638e+02,
7.290403481752945059e-01, 3.246951759540853004e+02, 1.179614954727290069e+03,
7.159885607208993363e-01]
m = [1.007070707070707005e+00]
p = collections.OrderedDict()
for idx, key in enumerate(bound_list.keys()):
p[key] = par[idx]
for i in range(1000):
try:
obj = package.class0(key='Key0', **p, _verbose=0)
#res = obj.get_vals(m)
except Exception as ex:
obj = None
#raise
template = "An exception of type {0} occurred. Arguments:\n{1!r}"
message = template.format(type(ex).__name__, ex.args)
print(message)
print("Done! "+str(i))