def test06_lock_unlock(self):
     'QueueSimple.lock()'
     qs = QueueSimple(self.qdir)
     data = 'foo'
     elem_name = 'foo.bar'
     elem_full_path = self.qdir + '/' + elem_name
     open(elem_full_path, 'w').write(data)
     self.assertEqual(qs.lock(elem_name), 1)
     self.failUnless(os.path.exists(elem_full_path + LOCKED_SUFFIX))
     qs.unlock(elem_name)
Exemplo n.º 2
0
#    print("# added element %i as %s" % (count, name))

# sample consumer

dirq = QueueSimple(queue_dir)
passes = 0
items = 0
elapsedtime = time()
logmessageinterval = 60  #seconds
WHEN2POST = 'queue'

while True:
    for name in dirq:
        if not dirq.lock(name):
            continue
        print("# reading element %s" % name)
        data = dirq.get(name)
        print data
        # one could use dirq.unlock(name) to only browse the queue...
        dirq.unlock(name)
        # print("# removing element %s" % name)
        # dirq.remove(name)
        items += 1
        print("# items processed: %s" % items)
    sys.exit()
    sleep(1)
    passes += 1
    if time() - elapsedtime > logmessageinterval:
        print 'pass %s, items %s, date %s' % (
            passes, items, datetime.datetime.utcnow().strftime("%Y%m%d%H%M%S"))
        elapsedtime = time()