title: proper way to use mongodb in multi-threading application
body: <p>I have server application with cron task (in own threads) and I want to insert data to mongodb database and I  wants to avoid deadlock or other multi-threading issues.</p>
  
  <p>my code:</p>
  
  <pre><code>from multiprocessing.dummy import Pool as ThreadPool
  from pymongo import MongoClient
  import sched
  import time
  
  TIME_INTERVAL = 3
  THREAD_NUMBER = 4
  
  s = sched.scheduler(time.time, time.sleep)
  pool = ThreadPool(THREAD_NUMBER)
  
  websites = [
      "website1",
      "website2",
      "website3",
      "website4",
  ]
  
  def insert_to_mongo(result):
      #that is proper way ?
      mongo_client = MongoClient('localhost', 27017)
      dic = mongo_client["cjgs"]["tracks"]
      dic.insert({"Result": result})
  
  def parsing_site(station):
      print "Doing stuff for ", station
      insert_to_mongo("Result for " + station)
  
  def recursion(sc, station):
      parsing_site(station)
      sc.enter(TIME_INTERVAL, 1, recursion, (sc, station,))
  
  def run_cron_task(station):
      s.enter(TIME_INTERVAL, 1, recursion, (s, station,))
      s.run()
  
  pool.map(run_cron_task, websites)
  </code></pre>
  
  <p>how to use mongodb in this case ? how to write this code in a more python style way with decorators and other syntactic sugar?</p>