I have a class with some methods, and a dict of dicts E which is shared between threads. I use the Threading.lock() class (instantiated as Elock) to read and write from E each time I need to.
One of the methods within the class looks like this:
Elock.acquire()
#print self.Num, E[key].keys()
if self.Num not in E[key].keys():
print '\n\nDisappeared!\n\n', self.Num, E[key].keys()
#DO STUFF
Elock.release()
return
else:
Elock.release()
What is really blowing my mind is that I will get
Disappeared!
17171875.0 [17175000.0, 17171875.0]
When I uncomment the print command before the conditional, I get what I'm expecting:
17171875.0 [17175000.0, 17171875.0]
As you can see, in both cases self.Num is in E[key].keys. Why is the conditional returning True and entering if clause?
Sometimes self.Num will be a float and the corresponding element in E[key].keys() will be an int. This should not be an issue anyway, and I think is not causing my problem. When I write
if float(self.Num) not in [float(x) for x in E[key].keys()]:
the behavior does not change.
Most puzzling is that IT ONLY BREAKS SOMETIMES! It works normally most of the time, but seems to return the wrong answer if the number ends with 5.0 (at least, that is the only time I have seen it break).
Aucun commentaire:
Enregistrer un commentaire