Python : While threading why does the conditional statement work differently?
<p>I was trying to write a simple function and call it from a thread for different values. The function worked perfectly when called normally. But as soon as we call it from a thread the conditional statements inside the function do not work.</p>

<pre><code>def func(count):
    print "In func count = {0}".format(count)
    if count == 3:
        print "If count = {0}".format(count)
        print "Sleeping as count = {0}".format(count)
    else:
        print "Else count = {0}".format(count)
        print "{0} so No sleep".format(count)
--------------------------------------------------
</code></pre>

<p>While calling the above function works perfectly.</p>

<pre><code>print func(2)
print func(3)
print func(4)
</code></pre>

<p>Output is :</p>

<pre><code>In func: count = 2
Printing Else Count = 2

In func: count = 3
Printing If Count = 3

In func: count = 4
Printing Else Count = 4


------------------------------
</code></pre>

<p>But while using the same function in a thread the behavior is different.</p>

<pre><code>thread_arr = []
for index in range(2,5,1):
    thread_arr.append(threading.Thread(target=func, args=("{0}".format(int(index)))))
    thread_arr[-1].start()
for thread in thread_arr:
    thread.join()
</code></pre>

<p>Output is :</p>

<pre><code>In func: count = 2
Printing Else Count = 2
In func: count = 3
Printing Else Count = 3
In func: count = 4
Printing Else Count = 4
</code></pre>

<p>Can anyone help why is the behavior different?</p>