title: How to create an infinite float number generator to be used as input to another function
body: <p>I want to simulate a stream of infinite float numbers.  If possible I want to add 1 sample every 10 seconds.</p>
  <p>Let's call it <code>stream_data</code>.</p>
  <p>And I want to make a calculation every time <code>stream_data</code> generates 100 samples and store the result of this calculation.</p>
  <p>When the stream reaches 100 samples, the chunk function (defined below) will create 2 chunks (list or arrays) of 50 samples each chunk.</p>
  <pre class="lang-none prettyprint-override"><code>chunk_1 = 50 samples
  chunk_2 = 50 samples
  </code></pre>
  <p>Chunk generator that gets samples from the <code>stream_data</code> as input:</p>
  <pre><code>def chunks(stream_data, n):
      &quot;&quot;&quot;Yield successive n-sized chunks from array.&quot;&quot;&quot;
      for i in range(0, len(stream_data), n):
          yield stream_data[i:i + n]
  </code></pre>
  <p>Then after the <code>stream_data</code> generates the first <strong>100 samples</strong> we will use <code>chunks function</code> to create <strong>2</strong> arrays or list of <strong>50 samples each:</strong></p>
  <p>Then calculate the difference of stardard deviation of the samples of size 50:</p>
  <pre><code>std_results = []
  
  # This line is just using the chunks function and it's 
  # initiate when the stream_data reaches 100 samples.
  for x in chunks(stream_data, 50):
      a = np.std(chunk_1)
      b = np.std(chunk_2)
      c = a - b
      std_results.append(c)
      # wait for next samples
  </code></pre>
  <p>This process should run until I abort so will follow this process:</p>
  <ol>
  <li>Initiate the <code>stream_data</code> generator --&gt; 1 sample at x seconds</li>
  <li>Once stream_data reach size 100 the chunks function will create 2 chunks of 50 elements each</li>
  <li>function2 will get these 2 chunks and perform the calculations as explained.</li>
  <li>Append the results to <code>std_results</code></li>
  <li>Once <code>stream_data</code> reaches another 100 samples the process repeats itself.</li>
  </ol>
  <p>I don't need to store the generated floats after the calculation is performed so if there's a way to clean them to save memory will be good.</p>
  <p><strong>What I did so far</strong></p>
  <p>I have the chunks function ready as explained above.  I think it could be used the it is now.</p>
  <p>I know I can use <code>while true</code>.</p>
  <p>The code below generates a random int every 5 seconds and generates the chunk but I don't know how to start the next 4 (4 to make it faster) samples all over again:</p>
  <pre><code>import time
  result = []
  lista = []
  starttime = time.time()
  while True:
      stream = np.random.randint(1,100)
      result.append(stream)
      print(result)
      if len(result) == 4:
          w=chunks(result,2)
          lista.append(w)
          print(lista)
          
      time.sleep(5.0 - ((time.time() - starttime) % 5.0))
  </code></pre>