title: Django ORM leaks connections when using ThreadPoolExecutor
body: <p>I'm using <code>ThreadPoolExecutor</code> to speed up data processing. The problem is that the thread pool creates new database connections and Django doesn't close them. I do have CONN_MAX_AGE in <code>settings.py</code> and I already tried to call <code>django.db.close_old_connections()</code>. </p>
  
  <p>Here is a code example:</p>
  
  <pre><code>def compute(job):
      result = FooModel.objects.filter(...).aggregate(...)
      return BarModel.objects.create(result)
  
  def process(dataset):
      thread_pool = ThreadPoolExecutor(max_workers=20)
      futures = []
  
      for job in dataset:
          futures += [thread_pool.submit(compute, job)]
  
      results = list(r.result() for r in wait(futures)[0])
      return results
  
  for i in range(0, 100):
      process(['foo', 'bar', 'qux'])
  </code></pre>
  
  <p>Is Django ORM able to terminate idle DB connections if they were started in another thread?</p>
  
  <hr>
  
  <p>UPD:
  Interestingly, Django doesn't even know about these connections:</p>
  
  <pre><code>&gt;&gt;&gt; from django.db import connections
  &gt;&gt;&gt; print(len(connections.all()))
  &gt;&gt;&gt; 2
  
  </code></pre>
  
  <pre><code>mypostgresdb=# select count(*) from pg_stat_activity;
   count 
  -------
     182
  (1 row)
  </code></pre>
  
  <p>And all workers threads were already closed for sure:</p>
  
  <pre><code>&gt;&gt;&gt; #  workers threads were closed:
  &gt;&gt;&gt; import threading
  &gt;&gt;&gt; threading.enumerate()
  [&lt;_MainThread(MainThread, started 140660203321088)&gt;]
  </code></pre>