def __queue__(self):
     ''' Starts a job or leaves it in the queue (thread safe) '''
     logging.debug("Attempting to acquire queue mutex ...")
     self.mutex.acquire()
     logging.debug("Successfully acquired queue mutex.")
     queue = list(Job.queue())  # Create a copy of the queue
     for job in queue:
         logging.info("Dispatching job: %s" % job.job_name)
         if len(job) == 0:
             job.status = u"COMPLETED"
             dbsession.add(job)
             dbsession.flush()
         else:
             algo = Algorithm.by_id(job.algorithm_id)
             weapon_systems = WeaponSystem.system_ready(algo)
             if weapon_systems is not None and 0 < len(weapon_systems):
                 logging.info("Weapon systems available: %d" % (
                     len(weapon_systems),
                 ))
                 thread.start_new_thread(
                     self.__crack__, 
                     (job, weapon_systems[0],)
                 )
             else:
                 logging.info("No available weapon systems at this time.")
     self.mutex.release()
 def __queue__(self):
     ''' Starts a job or leaves it in the queue (thread safe) '''
     logging.debug("Attempting to acquire queue mutex ...")
     self.mutex.acquire()
     logging.debug("Successfully acquired queue mutex.")
     queue = list(Job.queue())  # Create a copy of the queue
     for job in queue:
         logging.info("Dispatching job: %s" % job.job_name)
         if len(job) == 0:
             job.status = u"COMPLETED"
             dbsession.add(job)
             dbsession.flush()
         else:
             algo = Algorithm.by_id(job.algorithm_id)
             weapon_systems = WeaponSystem.system_ready(algo)
             if weapon_systems is not None and 0 < len(weapon_systems):
                 logging.info("Weapon systems available: %d" %
                              (len(weapon_systems), ))
                 thread.start_new_thread(self.__crack__, (
                     job,
                     weapon_systems[0],
                 ))
             else:
                 logging.info("No available weapon systems at this time.")
     self.mutex.release()