title: How to pass a function containing pymongo db to rq queue (bypassing the inabillity to seralize _thread.lock)?
body: <p>I have a db and a service that monitors it. I want to enqueue calls regarding said db to an <code>rq.Queue</code>:</p>
  <h2>callback.py</h2>
  <pre><code>from pymongo import MongoClient
  
  
  db_client = MongoClient(username='root', password='pass').db.collection
  
  
  def do_something(db):
      while not list(db.find({})):
          print('empty db')
      print('found something')
  </code></pre>
  <p>however, every try I had doing something like this</p>
  <pre><code>from redis import Redis; from rq import Queue; from allocator import db_client, do_something
  Queue(connection=Redis()).enqueue(do , (db_client, )
  </code></pre>
  <p>resulted in</p>
  <pre><code>TypeError: cannot pickle '_thread.lock' object
  </code></pre>
  <p>How can I bypass this and allow the queued function to interact with the db?</p>
  <p>Things I have tried:</p>
  <ol>
  <li>Using another serializer (dill - <code>TypeError: cannot pickle 'sqlite3.Connection' object</code>)</li>
  <li>Wrapping <code>do_something</code> in a class that owns the db - same error</li>
  </ol>