code: def run(self):
          
          while True:
              try:
                  doc = self.in_queue.get(True, QUEUE_TIMEOUT)
                  if doc == UDF.QUEUE_CLOSED:
                      self.in_queue.put(UDF.QUEUE_CLOSED)
                      break
                  self.session.add_all(y for y in self.apply(doc, **self.apply_kwargs))
                  self.out_queue.put(UDF.TASK_DONE)
              except Empty:
                  continue
          self.session.commit()
          self.session.close()
docs: This method is called when the UDF is run as a Process in a
          multiprocess setting The basic routine is: get from JoinableQueue,
          apply, put / add outputs, loop