I have a list of objects in python that I would regularly check and destroy some of them – those which haven’t been accessed lately (i.e. no method was called).
I can maintain the last time accessed and update it in every method, but is there any more elegant way to achieve this?
Use a decorator for the methods you want wrapped with the timestamp functionality, as @Marcelo Cantos pointed out.
Consider this example:
Edit: added
functools.wrapsas pointed out by @Peter Milley.