Example #1
0
 def empty(self):
     with filelock(self.filename,timeout=0.0) as lock:
         queue = load(self.filename,lock=lock,file_format='pickle')
         if len(queue.task_list) > 0:
             return False
         else:
             return True
Example #2
0
 def empty(self):
     with filelock(self.filename, timeout=0.0) as lock:
         queue = load(self.filename, lock=lock, file_format='pickle')
         if len(queue.task_list) > 0:
             return False
         else:
             return True
Example #3
0
 def check():
     with filelock(self.filename,timeout=0.0) as lock:
         queue = load(self.filename,lock=lock,file_format='pickle')
         if not queue.max_size is None and queue.unfinished_tasks >= queue.max_size:
             raise Full
         queue.unfinished_tasks += 1
         queue.task_list.append(task)
         save(queue,self.filename,lock=lock,file_format='pickle')
Example #4
0
 def check():
     with filelock(self.filename, timeout=0.0) as lock:
         queue = load(self.filename, lock=lock, file_format='pickle')
         if not queue.max_size is None and queue.unfinished_tasks >= queue.max_size:
             raise Full
         queue.unfinished_tasks += 1
         queue.task_list.append(task)
         save(queue, self.filename, lock=lock, file_format='pickle')
Example #5
0
 def check():
     with filelock(self.filename, timeout=0.0) as lock:
         queue = load(self.filename, lock=lock, file_format='pickle')
         queue.unfinished_tasks -= 1
         if queue.unfinished_tasks < 0:
             print 'warning: task_done() called too many times'
             queue.unfinished_tasks = 0
         save(queue, self.filename, lock=lock, file_format='pickle')
Example #6
0
 def check():
     with filelock(self.filename,timeout=0.0) as lock:
         queue = load(self.filename,lock=lock,file_format='pickle')
         queue.unfinished_tasks -= 1
         if queue.unfinished_tasks < 0:
             print 'warning: task_done() called too many times'
             queue.unfinished_tasks = 0                    
         save(queue,self.filename,lock=lock,file_format='pickle')
Example #7
0
 def check():
     with filelock(self.filename,timeout=0.0) as lock:
         queue = load(self.filename,lock=lock,file_format='pickle')
         try: 
             task = queue.task_list.pop(0)
             save(queue,self.filename,lock=lock,file_format='pickle')
         except IndexError:
             raise Empty
     return task
Example #8
0
 def check():
     with filelock(self.filename, timeout=0.0) as lock:
         queue = load(self.filename, lock=lock, file_format='pickle')
         try:
             task = queue.task_list.pop(0)
             save(queue, self.filename, lock=lock, file_format='pickle')
         except IndexError:
             raise Empty
     return task
Example #9
0
 def check():
     with filelock(self.filename,timeout=0.0) as lock:
         queue = load(self.filename,lock=lock,file_format='pickle')
         if len(queue.task_list): 
             task_list = queue.task_list
             queue.task_list = []
             save(queue,self.filename,lock=lock,file_format='pickle')
         else:
             raise Empty
     return task_list
Example #10
0
 def check():
     with filelock(self.filename, timeout=0.0) as lock:
         queue = load(self.filename, lock=lock, file_format='pickle')
         if len(queue.task_list):
             task_list = queue.task_list
             queue.task_list = []
             save(queue, self.filename, lock=lock, file_format='pickle')
         else:
             raise Empty
     return task_list
Example #11
0
 def __init__(self, filename, max_size=None, delay=0.5, new=False):
     self.filename = os.path.abspath(filename)
     self.delay = delay
     # start the queue data file if needed
     if not os.path.exists(self.filename) or new:
         queue = QueueData()
         queue.max_size = max_size
         if os.path.exists(self.filename):
             lock = filelock(self.filename, MASTER_TIMEOUT, self.delay)
         else:
             lock = None
         save(queue, self.filename, file_format='pickle', lock=lock)
Example #12
0
 def __init__( self, filename, max_size=None, delay=0.5, new=False):
     self.filename = os.path.abspath(filename)
     self.delay = delay
     # start the queue data file if needed
     if not os.path.exists(self.filename) or new:
         queue = QueueData()
         queue.max_size = max_size
         if os.path.exists(self.filename):
             lock = filelock(self.filename,MASTER_TIMEOUT,self.delay)
         else:
             lock = None
         save(queue,self.filename,file_format='pickle',lock=lock)
Example #13
0
        def check(task_list):
            with filelock(self.filename, timeout=0.0) as lock:
                queue = load(self.filename, lock=lock, file_format='pickle')

                if not queue.max_size is None:
                    n_extend = queue.max_size - queue.unfinished_tasks
                else:
                    n_extend = len(task_list)
                this_tasks = [task_list.pop(0) for i in range(n_extend)]

                queue.unfinished_tasks += n_extend
                queue.task_list.extend(this_tasks)

                if len(this_tasks):
                    save(queue, self.filename, lock=lock, file_format='pickle')

                if len(task_list):
                    raise Full
Example #14
0
 def check(task_list):
     with filelock(self.filename,timeout=0.0) as lock:
         queue = load(self.filename,lock=lock,file_format='pickle')
         
         if not queue.max_size is None:
             n_extend = queue.max_size-queue.unfinished_tasks
         else:
             n_extend = len(task_list)
         this_tasks = [ task_list.pop(0) for i in range(n_extend) ]
         
         queue.unfinished_tasks += n_extend
         queue.task_list.extend(this_tasks)   
         
         if len(this_tasks):
             save(queue,self.filename,lock=lock,file_format='pickle')
         
         if len(task_list):
             raise Full
Example #15
0
 def set(self, key, value):
     with filelock(self.filename, self.timeout, self.delay) as lock:
         cache = load(self.filename, lock=lock, file_format='pickle')
         cache[key] = value
         save(cache, self.filename, lock=lock, file_format='pickle')
Example #16
0
 def close(self):
     with filelock(self.filename,timeout=MASTER_TIMEOUT) as lock:
         os.remove(self.filename)
Example #17
0
 def close(self):
     with filelock(self.filename, timeout=MASTER_TIMEOUT) as lock:
         os.remove(self.filename)
Example #18
0
 def check():
     with filelock(self.filename, timeout=0.0) as lock:
         queue = load(self.filename, lock=lock, file_format='pickle')
         if queue.unfinished_tasks > 0:
             raise Full
Example #19
0
 def set(self,key,value):
     with filelock(self.filename,self.timeout,self.delay) as lock:
         cache = load(self.filename,lock=lock,file_format='pickle')
         cache[key] = value
         save(cache,self.filename,lock=lock,file_format='pickle')        
Example #20
0
 def check():
     with filelock(self.filename,timeout=0.0) as lock:
         queue = load(self.filename,lock=lock,file_format='pickle')
         if queue.unfinished_tasks > 0:
             raise Full