Skip to main content
4 of 4
deleted 6 characters in body
alex_noname
  • 33.2k
  • 6
  • 95
  • 110

Thread pool works as follows, it starts a task in a thread and until it returns control the thread is busy, even if it sleeps. Therefore, if you want to run them in parallel, you have to either use multiple threads or use asyncio coroutines.

Here is asyncio sample:

import asyncio import time def foo(): print('Start ...') time.sleep(5) print('... End') async def main(): loop = asyncio.get_running_loop() count = range(2) futures = [loop.run_in_executor(None, foo) for i in count] results = await asyncio.gather(*futures) asyncio.run(main()) 

Output

Start ... Start ... ... End ... End 
alex_noname
  • 33.2k
  • 6
  • 95
  • 110