Discussion of Issue
The code freezes because you are using a while
loop with a condition whose variables do not change within the loop. Therefore, if the condition evaluates to True
the first time through the loop, it will evaluate to True
indefinitely, (i.e. the code 'hangs'). Typically (unless you want the loop to run forever) one or more variables within a while
loop will change within the loop. A very simple example is,
while index < 10:
plt.plot(x_data[index], y_data[index])
index += 1 # Here the index changes.
Note: For these purposes it is more common to use for index in range(10):
or better yet for xd, yd in zip(x_data, y_data): plt.plot(xd, yd)
rather than a while
loop because then you don't need to have the index += 1
line, and it is clearer at the beginning of the loop what is going on. I merely provided this as a clear example use of while
.
Even if the conditional variables do change within the loop (i.e. if you're only providing a snippet of your while
loop), it is possible that the conditional statement always evaluates to True
. In this case, again, you will never exit the while
loop and your code will 'hang'.
Potential Solutions
There are several ways you could fix your problem depending on what you are trying to do:
If you just want to plot your data once, use if
instead of while
.
If you are only showing us a snippet of your loop and the variables in the conditional statement do change within the loop, I would recommend:
A) starting by placing a print(np.any((np.log10((O3 / HB)) < 0.61 / (np.log10(N2 / HA) - 0.05) + 1.3).any()))
at the top of your loop and run your code. I presume this will dump True
to your console.
B) You could then start to break this statement apart using more print statements such as print('N2: %f' % N2)
to understand why your statement is never evaluating to False
and therefore you are never exiting the loop.