runtime
352 / 500
question 352 Memory & Python Internals · easy

Fix the session registry that never forgets

A web app keeps its open sessions in a registry. After a day the server's memory is full: open_count() keeps growing although users log out, and closed sessions are never freed. Fix close so a closed session is marked closed and the registry lets go of it.

ClassSessionRegistry() with start(session_id, user), close(session_id) and open_count()
close(session_id)set the session's closed to True and remove it from the registry; an unknown ID still raises KeyError
Ruleonce closed, the registry must not keep the session object alive

Loading your progress…

Fix the session registry that never forgets — Python practice · Runtime