title: How to get quantity of active threads in python async
body: <p>I am writing an asynchronous python program that does many async functions, but unfortunately has to read a serial port, and <code>serial</code> is not async compatible, so I need to utilize a synchronous function to read the serial port, but don't want to block the async functions.</p>
  <p>I have managed to complete this by doing:</p>
  <pre><code>import asyncio
  import time
  
  def serialReader():
      while True:
          print(&quot;waiting for new serial values&quot;)
          time.sleep(4)#simulated waiting on serial port
          return &quot;some serial values&quot;
  
  async def func1():
      while True:
          print(&quot;function 1 running&quot;)
          await asyncio.sleep(1)
  
  async def serialManager():
      loop = asyncio.get_running_loop()
      while True:
          result = await loop.run_in_executor(None, serialReader)
          print(result)
  
  async def main(): 
      func1Task = asyncio.create_task(func1())
      func2Task = asyncio.create_task(serialManager())
      await func2Task
  
  
  asyncio.run(main())
  </code></pre>
  <p>But my concern here is that I may be spawning multiple threads that will pile up eventually and cause problems. If this is a valid concern, is there a way to see the active threads?</p>