title: How to evualate a function in a while loop
body: <p>I am trying to stream data in real time while comparing two values. However, it seems as if the function is only being evaluated once. However, <code>time.sleep</code> is also being ran, because it pauses in between loops. However the time is always the same.</p>
  <pre><code>x = f'https://api.polygon.io/v1/last/stocks/SPY?{key}'
  def get_data():
      time.sleep(5)
      data = requests.get(x)
      json_data = data.json()
      
      #last price, datetime object
      print ((json_data['last'])['price'], epoch_to_date_time( (json_data['last'])['timestamp'] ).__str__())
      return (json_data['last'])['price']
  
  
  def while_no_match(x):
      counter = 0
      while get_data()!=x and counter &lt; 5 :
          get_data()
          counter +=1
  
  if __name__ == '__main__':
      while_no_match(100)
  </code></pre>
  <pre><code>316.63 2020-07-08 19:01:42.457000
  316.63 2020-07-08 19:01:42.457000
  316.63 2020-07-08 19:01:42.457000
  316.63 2020-07-08 19:01:42.457000
  316.63 2020-07-08 19:01:42.457000
  316.63 2020-07-08 19:01:42.457000
  316.63 2020-07-08 19:01:42.457000
  316.63 2020-07-08 19:01:42.457000
  316.63 2020-07-08 19:01:42.457000
  316.63 2020-07-08 19:01:42.457000
  316.63 2020-07-08 19:01:42.457000
  </code></pre>