Re: weird dict problem, how can this even happen?

2008-12-19 Thread Scott David Daniels
Joel Hedlund wrote: Scott David Daniels wrote: Perhaps your hash function could be something like: I'm not sure I understand what you're suggesting. /Joel Sorry, a half-thought out idea based on the fact that you wanted a consistent hash for a varying dictionary. The given dictionary subcl

Re: weird dict problem, how can this even happen?

2008-12-19 Thread Joel Hedlund
Joel Hedlund wrote: First off, please note that I consider my problem to be solved, many thanks to c.l.p and especially Duncan Booth. But of course continued discussion on this topic can be both enlightening and entertaining as long as people are interested. So here goes: heh, nothing like a

Re: weird dict problem, how can this even happen?

2008-12-17 Thread Joel Hedlund
Steven D'Aprano wrote: On Tue, 16 Dec 2008 14:32:39 +0100, Joel Hedlund wrote: Duncan Booth wrote: Alternatively give up on defining hash and __eq__ for FragmentInfo and rely on object identity instead. Object identity wouldn't work so well for caching. Objects would always be drawn as they ap

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Steven D'Aprano
On Wed, 17 Dec 2008 02:10:31 +0100, Joel Hedlund wrote: > Scott David Daniels wrote: >> Perhaps your hash function could be something like: > > I'm not sure I understand what you're suggesting. Neither am I, since you've removed the hash function which might have given readers a clue. *wink*

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Steven D'Aprano
On Tue, 16 Dec 2008 14:32:39 +0100, Joel Hedlund wrote: > Duncan Booth wrote: >> I think you probably are correct. The only thing I can think that might >> help is if you can catch all the situations where changes to the >> dependent values might change the hash and wrap them up: before >> changin

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Joel Hedlund
Scott David Daniels wrote: Perhaps your hash function could be something like: I'm not sure I understand what you're suggesting. /Joel -- http://mail.python.org/mailman/listinfo/python-list

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Scott David Daniels
Joel Hedlund wrote: Duncan Booth wrote: I think you probably are correct. The only thing I can think that might help is if you can catch all the situations where changes to the dependent values might change the hash and wrap them up: before changing the hash pop the item out of the dict, then

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Joel Hedlund
Duncan Booth wrote: I think you probably are correct. The only thing I can think that might help is if you can catch all the situations where changes to the dependent values might change the hash and wrap them up: before changing the hash pop the item out of the dict, then reinsert it after the

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Duncan Booth
Joel Hedlund wrote: > I should probably do this with lists instead because I can't really > think of a way of salvaging this. Am i right? > I think you probably are correct. The only thing I can think that might help is if you can catch all the situations where changes to the dependent value

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Arnaud Delobelle
Joel Hedlund writes: > I'm having a very hard time explaining why this snippet *sometimes* > raises KeyError: > > snippet: >> print type(self.pool) >> for frag in self.pool.keys(): >> if frag is fragment_info: >> print "the fragment_info *is* in the pool", hash(frag), >> hash(fragmen

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Joel Hedlund
Duncan Booth wrote: It could happen quite easily if the hash value of the object has changed since it was put in the dictionary. what does the definition of your core.gui.FragmentInfo object look like? Dunno if it'll help much, but: class FragmentInfo(object): def __init__(self, renderer,

Re: weird dict problem, how can this even happen?

2008-12-15 Thread Duncan Booth
Joel Hedlund wrote: > I would very much like an explanation to this that does not involve > threads, because I haven't made any that I'm aware of. I can't even > understand how this could happen. How do I even debug this? > It could happen quite easily if the hash value of the object has chang

weird dict problem, how can this even happen?

2008-12-15 Thread Joel Hedlund
I'm having a very hard time explaining why this snippet *sometimes* raises KeyError: snippet: print type(self.pool) for frag in self.pool.keys(): if frag is fragment_info: print "the fragment_info *is* in the pool", hash(frag), hash(fragment_info), hash(frag) == hash(fragment_info)