Possible Stack Overflow in Python, no error raised
I'm using Python 3.7, VSCode for some geographic data processing (forest fire detection). My script is exiting in the middle of a recursive function, without any error nor traceback...
This is the code that crash (I deleted every line that seemed not essential to the understanding of the function, trying to make it more clear) :
def SentinelSecondaire(dicoRef, dicoSRef, Rels, SNT, SRefTraite=list()):
for sref, srefv in sorted(dicoSRef.items(), key=lambda x: x[1]):
if sref not in SRefTraite:
Slies1 = list()
for r in Rels:
if r[0] == sref:
if r[3] not in dicoSRef.keys() and r[3] in SNT:
Slies1.append(r[3])
elif r[3] == sref:
if r[0] not in dicoSRef.keys() and r[0] in SNT:
Slies1.append(r[0])
idRef = dicoSRef[sref]
Slies1 = list(set(Slies1))
if len(Slies1) > 0:
for s in Slies1:
dicoRef[idRef].append(s)
dicoSRef[s] = idRef
if s in SNT:
SNT.remove(s)
SSec = SentinelSecondaire(dicoRef, dicoSRef, Rels, SNT, SRefTraite)
dicoRef = SSec[0]
for ss in SSec[1].keys():
if ss not in dicoSRef.keys():
dicoSRef[ss] = idRef
SNT = SSec[2]
SRefTraite.append(sref)
return [dicoRef, dicoSRef, SNT]
where
Rels = [["D1", ..., date, "S1", ..., date1], ..., ["D2", ..., date, "S400", ..., date1]]
dicoRef = {
"D1": ["S1", "S30"],
"D2": ["S201", "S400"]
}
dicoSref = {
"S1": "D1",
"S30": "D1",
...,
"S400": "D2"
} # Some kind of reversed dicoRef
I have of course sys.setrecursionlimit(high_enought) and that is why I think that I'm getting a stack overflow error. I'm looking for a way to overcome this issue, either changing my function to an iterative one or to a tail-recursive one, or pushing the stack size limit farther... This looks like an DFS graph function, but the for loops are confusing me. I didn't wrote the program, I'm just trying to make it work with new (bigger) set of data.
Any kind of help on the global architecture or tips I could use would be greatly appreciated.
EDIT : link to the mre code and file :
https://github.com/Kaupahcox/Graph_issue.git
from Recent Questions - Stack Overflow https://ift.tt/3fTAQ3g
https://ift.tt/eA8V8J
Comments
Post a Comment