title: Python file scan application with multithreading
body: <p>How to use multithreading in this code and limit the thread; example 4 thread.</p>
  
  <pre><code>import os
  import glob
  from pymongo import Connection
  from gridfs import GridFS
  
  db = Connection().microfilm
  fs = GridFS(db)
  
  def scandirs(path):
      for currentFile in glob.glob( os.path.join(path, '*') ):
          if os.path.isdir(currentFile):
              print 'Entering directory: ' + currentFile
              scandirs(currentFile)
  
          base, ext = os.path.splitext(currentFile)
          if ( ext == '.tif'):
                  print "Processing file: " + currentFile
                  fName = os.path.basename(currentFile)
                  with open(currentFile) as gfsFile:
                          oid = fs.put(gfsFile, content_type="image/tiff", filename=fName)
  
  scandirs('./')
  </code></pre>
  
  <p>Thanks in advance.</p>