I am using threads in a python program and recently found a problem where a float is not being interpreted correctly and whenever I go to print it out in pdb or in a logging statement, it shows up correctly most of the time.
Oddly, it takes a different amounts of prints to show up in these two threads I just ran. Also the first two prints use the same format, but the value still changes in thread 1.
for x in imports:
if float(x.prob) == 0.0:
logging.debug(float(x.prob))
logging.debug(float(x.prob))
logging.debug(x.prob)
logging.debug(str(x.prob))
logging.debug(str(float(x.prob)))
import pdb; pdb.set_trace()
[DEBUG] (Thread-1 ) 0.0
[DEBUG] (Thread-1 ) 0.0592
[DEBUG] (Thread-1 ) 0.0592
[DEBUG] (Thread-1 ) 0.0592
[DEBUG] (Thread-1 ) 0.0592
[DEBUG] (Thread-2 ) 0.0
[DEBUG] (Thread-2 ) 0.0
[DEBUG] (Thread-2 ) 0
[DEBUG] (Thread-2 ) 0.0592
[DEBUG] (Thread-2 ) 0.0592
and
(Pdb) float(x.prob) == 0.0
False
What is the cause? what can I do so it's interpreted correctly the first time?
Similar to this question: https://stackoverflow.com/questions/2485338/pdb-show-different-variable-values-than-print-statements