Python pdb computes value 774 but program assigns 836
<p>I'm sure I am missing something here, but I find this very weird.</p>

<p>In <code>pdb</code> I get to the following step...</p>

<pre><code> Importing data...
&gt; /usr/local/lib/python2.7/dist-packages/tensorflow/tensorflow/scroll/marching_cube.py(111)read_data()
-&gt; n_cubes = int((n_slices - n_input_z) * int(math.ceil((x_dimension - n_input_x)/step_size)) * int(math.ceil((y_dimension - n_input_y)/step_size)))
</code></pre>

<p>When I compute the right hand side of the assignment, I get <code>774</code> -- which is the correct value. I can prove it by doing the computation directly in <code>pdb</code>...</p>

<pre><code>(Pdb) int((n_slices - n_input_z) * int(math.ceil((x_dimension - n_input_x)/step_size)) * int(math.ceil((y_dimension - n_input_y)/step_size)))
774
</code></pre>

<p>But watch this... when I go to the next line via the <code>n</code> command, <code>n_cubes</code> is suddenly assigns the value <code>836</code>...</p>

<pre><code>&gt; /usr/local/lib/python2.7/dist-packages/tensorflow/tensorflow/scroll/marching_cube.py(111)read_data()
-&gt; n_cubes = int((n_slices - n_input_z) * int(math.ceil((x_dimension - n_input_x)/step_size)) * int(math.ceil((y_dimension - n_input_y)/step_size)))
(Pdb) int((n_slices - n_input_z) * int(math.ceil((x_dimension - n_input_x)/step_size)) * int(math.ceil((y_dimension - n_input_y)/step_size)))
774
(Pdb) n
&gt; /usr/local/lib/python2.7/dist-packages/tensorflow/tensorflow/scroll/marching_cube.py(112)read_data()
-&gt; input_4d_volume = np.empty((n_cubes,n_input_z,n_input_x,n_input_y))
(Pdb) n_cubes
836
</code></pre>

<p>To prove the computation should be <code>774</code> I will print out all variables involved in the computation...</p>

<pre><code>(Pdb) n_slices
49
(Pdb) n_input_z
48
(Pdb) x_dimension
396
(Pdb) n_input_x
48
(Pdb) step_size
8
(Pdb) y_dimension
198
(Pdb) n_input_y
48
</code></pre>

<p>Try setting the breakpoint at the start of the function being run as a thread, or within its <code>while true:</code> loop if it has one, by adding this:</p>

<pre><code>import pdb
pdb.set_trace()
</code></pre>

<p>Then run the script normally (<em>not</em> through <code>pdb</code>) and execution will break into the debugger when the thread starts. Setting a breakpoint this way allows <code>pdb</code> to be run within the child thread where it will have access to <code>n_cubes's</code> value.</p>

python pdb