← Lesson
Detect Tool Thrash
Joeven
Run
Reset
Python loads on first run
def thrash(events, limit=3): counts = {} for name, args in events: key = name + "|" + str(sorted(args.items())) counts[key] = counts.get(key, 0) + 1 if counts[key] >= limit: return {"stop": "cannot: tool thrash", "key": key, "n": counts[key]} return {"stop": None, "n": max(counts.values()) if counts else 0} print(thrash([ ("search", {"q": "oom"}), ("search", {"q": "oom"}), ("search", {"q": "oom"}), ])) print(thrash([ ("search", {"q": "oom"}), ("search", {"q": "disk"}), ("finish", {"text": "x"}), ]))
Run to execute this in your browser. Nothing is sent to a server.