title: Return a value from function without waiting for it to complete every time in Python
body: <p>I've already read multiple forum threads, but still wanted to ask a specific question. Maybe someone can suggest something better.</p>
  <p>So, there's a main loop which iterates through a list. The list itself is generated with a function which returns it in 30-50 seconds (after appending items to it). What is the best way to get the recent complete list without waiting for it to be generated when called every time?</p>
  <p>Here's a simple example:</p>
  <pre><code>def check_list():
      list1 = [1, 2, 3, 4]
      list_upd = []
  
      for i in list1:
          if 4 &gt; i &gt; 1:
              list_upd.append(i)
      return list_upd # return the updated list
  
  while True:
      print(&quot;start&quot;) # we wait for 30 sec for the list to be generated
  
      for i in check_list():
           print(i)
      
      print(&quot;finish&quot;) # iterating through the list is completed
  </code></pre>
  <p>The idea is to be able to get the updated list no matter when you call the function without waiting for it to complete every time. It's not too important to get the latest generated list (previous one is fine too). A possible option is to write it to a file, then read it from there and update it in the background. Should probably use asyncio for it too. Are there some better options without writing to a file?</p>
  <p>Thanks</p>