title: how to terminate python script using while loop and get the result?
body: <p>i would like to generate random numbers for 5 minutes. after that, i would like to know the most common numbers.</p>
  
  <p>my question is:</p>
  
  <p>I am not sure about how much time I need. Can i MANUALLY terminate the script at 1 minute or 1 minute 19 seconds and get the result</p>
  
  <p>my code is as follows:</p>
  
  <pre><code>import random
  from collections import Counter
  t_end = time.time() + 60*5
  numbers = []
  while time.time() &lt; t_end:
      number=''.join(map(str, [random.randint(0,9)for value in range(0,4)]))
      numbers.append(number)
  
  print(Counter(numbers))
  </code></pre>