I suspect there's something else going on here, or your comments data is far different than I'm supposing.
Your flatten method works just fine for me with a tree of 600 comments. In fact, it works fine with 600,000 comments (recurs. lim. 1000)
Example test script:
https://pastebin.com/6Mdvu2WL
Without seeing your other code, I don't know what the issue you're running into. At a wild guess, is it possible your graph is not acyclic?
#Recursion #python #graph #cyclic #acyclic
I remember seeing this gif, the #Hasselhoff #Recursion, almost twenty years ago. It still mesmerizes me to this day.
#Covidiots in action... I wonder if they are able to hold a thought for longer than half a minute. #facepalm
---
RT @amir42
@randoCDN @ColetteMandin @elonmusk Let me circularly refer to the topic we are discussing... I'm out.
https://twitter.com/ColetteMandin/status/1596153334725251076?s=19
https://twitter.com/amir42/status/1596561185469784065
#COVIDIOTS #facepalm #Recursion