Design thought for callbacks

Chris Angelico rosuav at gmail.com
Sun Feb 22 17:41:04 EST 2015


On Mon, Feb 23, 2015 at 9:29 AM, Laura Creighton <lac at openend.se> wrote:
> But that is not so surprising.  How many people use WeakSets for
> _anything_?  I've never used them, aside from 'ooh! cool shiny
> new language feature!  Let's kick it around the park!'  That people
> aren't familiar with WeakSets doesn't mean all that much.

I haven't used weak *sets*, but I've used weak *mappings* on occasion.
It's certainly not a common thing, but they have their uses. I have a
MUD which must guarantee that there be no more than one instance of
any given room (identified by a string that looks like a Unix path),
but which will, if it can, flush rooms out of memory when nothing
refers to them. So it has a mapping from the path strings to the
instances, but with weak refs for the instances; if anything else is
referring to that instance (eg a player character in the room), it'll
hang around, and any time anyone else needs that room, they'll get the
same instance back from the mapping; but any time the garbage
collector notices that a room can be disposed of, it will be.

Definitely not common though.

ChrisA



More information about the Python-list mailing list