title: Sleep after yield inside an object method is not working python
body: <p>I want to monitor my servers after every few seconds. I have a generator inside an object method which will return overall metrics and after that it should wait for a while and check again:</p>
  
  <pre><code>def ping_servers(self):
      while True:
          all_server_metrics = {}
          for server in self.servers:
              response = requests.get(server, timeout=self.timeout_secs)
              server_metrics = {
                  'response_time': response.elapsed.total_seconds(),
                  'response_code': response.status_code,
              }
              all_server_metrics[server] = server_metrics
          yield json.dumps(all_server_metrics)
          time.sleep(self.period_secs)
  </code></pre>
  
  <p>Here it will not sleep at all. But if I put <code>time.sleep()</code> at the beginning of the while loop it will sleep for a given period of time. What could be the reason, why it is not sleeping?</p>
  
  <p>This is the code where I call above method:</p>
  
  <pre><code>monitoring = MonitoringService(period_secs=30, timeout_secs=5)
  
  while True:
      ping_results = next(monitoring.ping_servers())
      print(ping_results)
  </code></pre>