title: How to call mutiple function at the same time without waiting for function completed
body: <p>I want to write a code to ping multiple IPs at the same time. The function is as following:</p>
  <pre><code>import multiprocessing
  import subprocess
  
  IPs = {&quot;google&quot;: &quot;8.8.8.8&quot;,
         &quot;google2&quot;:&quot;8.8.4.4&quot;,
         &quot;cloudflare&quot;: &quot;1.1.1.1&quot;,
          &quot;cloudflare2&quot;:&quot;1.0.0.1&quot;
         } # not fixed length, different number of IPs each time
  
  def pinghost(name, host):
      print(f&quot;start ping {name} - {host}&quot;)
      cmd = [&quot;ping&quot;, host]
      ping_reply = subprocess.check_output(cmd)
      print(ping_reply)
      print(f&quot;end ping {name} - {host}&quot;)
  
  def main(IPs):
      p = multiprocessing.Pool()
      for i in IPs:
          print(i, IPs[i])
          p.apply_async(func=pinghost(i, IPs[i]))
      p.close()
      p.join()
  
  main(IPs)
  </code></pre>
  <p>Even though I used apply_async, looks like it's still waiting for ping these IPs one by one.</p>
  <pre><code>google 8.8.8.8
  start ping google - 8.8.8.8
  b'\r\nPinging 8.8.8.8 with 32 bytes of data:\r\nReply from 8.8.8.8: bytes=32 time=12ms TTL=116\r\nReply from 8.8.8.8: bytes=32 time=12ms TTL=116\r\nReply from 8.8.8.8: bytes=32 time=13ms TTL=116\r\nReply from 8.8.8.8: bytes=32 time=23ms TTL=116\r\n\r\nPing statistics for 8.8.8.8:\r\n    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),\r\nApproximate round trip times in milli-seconds:\r\n    Minimum = 12ms, Maximum = 23ms, Average = 15ms\r\n'
  end ping google - 8.8.8.8
  google2 8.8.4.4
  start ping google2 - 8.8.4.4
  b'\r\nPinging 8.8.4.4 with 32 bytes of data:\r\nReply from 8.8.4.4: bytes=32 time=13ms TTL=116\r\nReply from 8.8.4.4: bytes=32 time=10ms TTL=116\r\nReply from 8.8.4.4: bytes=32 time=14ms TTL=116\r\nReply from 8.8.4.4: bytes=32 time=9ms TTL=116\r\n\r\nPing statistics for 8.8.4.4:\r\n    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),\r\nApproximate round trip times in milli-seconds:\r\n    Minimum = 9ms, Maximum = 14ms, Average = 11ms\r\n'
  end ping google2 - 8.8.4.4
  cloudflare 1.1.1.1
  start ping cloudflare - 1.1.1.1
  b'\r\nPinging 1.1.1.1 with 32 bytes of data:\r\nReply from 1.1.1.1: bytes=32 time=8ms TTL=58\r\nReply from 1.1.1.1: bytes=32 time=5ms TTL=58\r\nReply from 1.1.1.1: bytes=32 time=9ms TTL=58\r\nReply from 1.1.1.1: bytes=32 time=14ms TTL=58\r\n\r\nPing statistics for 1.1.1.1:\r\n    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),\r\nApproximate round trip times in milli-seconds:\r\n    Minimum = 5ms, Maximum = 14ms, Average = 9ms\r\n'
  end ping cloudflare - 1.1.1.1
  cloudflare2 1.0.0.1
  start ping cloudflare2 - 1.0.0.1
  b'\r\nPinging 1.0.0.1 with 32 bytes of data:\r\nReply from 1.0.0.1: bytes=32 time=13ms TTL=58\r\nReply from 1.0.0.1: bytes=32 time=11ms TTL=58\r\nReply from 1.0.0.1: bytes=32 time=9ms TTL=58\r\nReply from 1.0.0.1: bytes=32 time=12ms TTL=58\r\n\r\nPing statistics for 1.0.0.1:\r\n    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),\r\nApproximate round trip times in milli-seconds:\r\n    Minimum = 9ms, Maximum = 13ms, Average = 11ms\r\n'
  end ping cloudflare2 - 1.0.0.1
  </code></pre>
  <p>So how can I ping these IPs at the same time？（call the function at the same time and don't wait for the result）</p>
  <p>I also tried aysncio, the same, it ping IPs one by one.</p>
  <pre><code>async def pinghost(name, host):
      print(f&quot;start ping {name} - {host}&quot;)
      cmd = [&quot;ping&quot;, host]
      ping_reply = subprocess.check_output(cmd)
      print(ping_reply)
      print(f&quot;end ping {name} - {host}&quot;)
  
  async def main(IPs):
      for i in IPs:
          print(i)
          await pinghost(i, IPs[i])
  
  asyncio.run(main(IPs))
  </code></pre>