title: Python asyncio non blocking for loop
body: <p>(I used Python 3.7)</p>
  
  <pre><code>import asyncio
  
  
  result = 0
  
  
  async def sub1():
      global result
      print('[*] sub1() start')
      for i in range(1, 10000000):
          result += i
      print('[*] sub1() end')
  
  async def sub2():
      global result
      print('[*] sub2() start')
      for i in range(10000000, 20000000):
          result += i
      print('[*] sub2() end')
  
  async def main():
      await asyncio.gather(
          asyncio.create_task(sub1()),
          asyncio.create_task(sub2()),
      )
  
  
  asyncio.run(main())
  </code></pre>
  
  <p>When I execute above code, it's result is</p>
  
  <pre><code>[*] sub1() start
  [*] sub1() end
  [*] sub2() start
  [*] sub2() end
  [Finished in 1.7s]
  </code></pre>
  
  <p>You know that, <code>sub2()</code> is started after <code>sub1()</code> finished.</p>
  
  <p>It seems doesn't work in parallel.</p>
  
  <p>I want to give control over to <code>sub2()</code> until <code>sub1()</code> finished.</p>
  
  <p>Maybe I have to insert <code>await</code> to somewhere, but I don't know where is the point.</p>
  
  <p><strong>Question</strong></p>
  
  <p>How can I execute both functions like parallel using for loop?</p>
  
  <p>Thanks.</p>