当前位置: 首页>>代码示例>>Python>>正文


Python HotQueue.consume方法代码示例

本文整理汇总了Python中hotqueue.HotQueue.consume方法的典型用法代码示例。如果您正苦于以下问题:Python HotQueue.consume方法的具体用法?Python HotQueue.consume怎么用?Python HotQueue.consume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hotqueue.HotQueue的用法示例。


在下文中一共展示了HotQueue.consume方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RedisInput

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
class RedisInput(object):
    input_name = "redis"

    def __init__(self, host, queue, port=6379):
        self.host = host
        self.port = port
        self.queue = queue

    def handle_input(self):
        try:
            self.queue = HotQueue(self.queue, serializer=json, host=self.host, port=self.port, db=0)

            for data in self.queue.consume():
                for fmt in self.format_modules:
                    if fmt.bind and self.input_name in fmt.bind:
                        data = fmt.decode(data)

                self.output_threads.write(data)
        except Exception as err:
            raise EveConnectionError(err)

    def run(self, format_modules, output_modules):
        # Start output threads
        self.format_modules = format_modules
        self.output_modules = output_modules
        self.output_threads = OutputThreads(self.output_modules, self.format_modules)
        while True:
            try:
                self.handle_input()
            except EveConnectionError as err:
                logger.error("connection error in input handler %s: %r - retrying in 1 second" % (self.input_name, err))
                sleep(1)
开发者ID:Crapworks,项目名称:eve,代码行数:34,代码来源:redis.py

示例2: subscribe_greenlet

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
 def subscribe_greenlet(ps, connection_thread_id):
     queue = HotQueue("connection_thread_id_queue=" + str(connection_thread_id))
     for msg in queue.consume():
         try:
             cmd = json.loads(msg)
             if cmd['cmd'] == 'subscribe':
                 ps.subscribe('uuid=' + cmd['params'])
             elif cmd['cmd'] == 'subscribe':
                 ps.unsubscribe('uuid=' + cmd['params'])
         except:
             pass
开发者ID:CaliopeProject,项目名称:CaliopeServer,代码行数:13,代码来源:dispatcher.py

示例3: Main

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
def Main():

	config = file_read('config.json')
	config = json.loads(config)
	HOST = config['mongohost']
	PORT = config['port']
	DB_NAME = config['database_name']
	LISTENER_QUEUE = config['listener_queue']
	RESPONSE_QUEUE = config['response_queue']

	file_dir = config['repo_directory']
	client = MongoClient(HOST,PORT)
	
	db = client[DB_NAME]
	
	listen = HotQueue(LISTENER_QUEUE,serializer=json)

	response = HotQueue(RESPONSE_QUEUE,serializer=json)

	r = redis.StrictRedis(host='localhost', port=6379, db=0)

	print "\nPython-Redis-Listener-Started "

	for item in listen.consume():
		
		files = []
		for _file  in item['files']:
			files.append(diff_file(_file['name'],_file['path'],_file['isnew'],_file['tag'],db,item['repoid'],file_dir))
		
		commits = {
					'changes'  : files,
					'desc'     : item['desc'],
					'created'  : datetime.datetime.utcnow(),
					#'comment'  : [],
					'repo'     : {'id':ObjectId(item['repoid']),'slug':item['reposlug']},
					'user'     : {'id':ObjectId(item['userid']),'username':item['username']}
				}

		commitid = db.commits.insert(commits)
		
		db.repos.update({'_id':commits['repo']['id']},{'$push':{'commits':commitid}})
		
		db.users.update({'_id':commits['user']['id']},{'$push':{'commits':commitid}})
		
		responseobj= {'commitid':str(commitid),'userid':str(commits['user']['id'])}

		#response.put(responseobj)
		r.publish('cy-pullcommits', json.dumps(responseobj))
		
		print commits
开发者ID:abhishekjairath,项目名称:codeyard,代码行数:52,代码来源:api.py

示例4: main

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
def main():
    queue = HotQueue(main_config.INDEX_QUEUE, 
                     host=main_config.REDIS_HOST, 
                     port=main_config.REDIS_PORT)
    index = get_index(main_config.WHOOSH_INDEX_DIR)
    writer = BufferedWriter(index, limit=10)
    try:
        for doc_id in queue.consume():
            print "looking at {}".format(doc_id)
            doc = Document.query.get(doc_id)
            if doc:
                write_doc(doc, writer)
            else:
                print "no doc with doc_id {}".format(doc_id)
    finally:
       writer.close()
开发者ID:andytom,项目名称:searchr-server,代码行数:18,代码来源:index_deamon.py

示例5: test_from_key

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
 def test_from_key(self):
     """Test the HotQueue.from_key static method"""
     redis = Redis()
     queues = {
         '_test:tens': range(10, 20),
         '_test:twenties': range(20, 30),
         '_test:thirties': range(30, 40)
     }
     for name, values in queues.items():
         q = HotQueue(name)
         q.put(*values)
     
     for key in redis.keys('hotqueue:_test:*'):
         q = HotQueue.from_key(key)
         self.assertEqual(
             list(q.consume(block=False)),
             queues[q.name]
         )
开发者ID:eyeseast,项目名称:hotqueue,代码行数:20,代码来源:tests.py

示例6: queue_processor

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
def queue_processor():
        queue = HotQueue("postprocessing_queue")
        ocr = OCR.Engine()

        for uuid in queue.consume():
            print str(uuid)
            dm = DocumentManager()
            doc = dm.getDocument(uuid)
            print str(doc.url)
            url = urlparse(doc.url)
            filename = os.path.join(UPLOAD_FOLDER, url.path)
            m = magic.Magic()
            print filename + ' ' + str(m.id_filename(filename))

            if 'PDF' in  str(m.id_filename(filename)):
                pdf_text = PDFProcessor.extractContent(str(filename))
                cm = ContentDocument()
                cm.content = unicode(pdf_text, encoding='utf-8')
                cm.save()
                #ocr_text = ocr.interpret(str(filename))
                print pdf_text
开发者ID:CaliopeProject,项目名称:CaliopeServer,代码行数:23,代码来源:processor.py

示例7: HotQueueTestCase

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
class HotQueueTestCase(unittest.TestCase):
    
    def setUp(self):
        """Create the queue instance before the test."""
        self.queue = HotQueue('testqueue')
    
    def tearDown(self):
        """Clear the queue after the test."""
        self.queue.clear()
    
    def test_arguments(self):
        """Test that HotQueue.__init__ accepts arguments correctly, and that
        the Redis key is correctly formed.
        """
        kwargs = {
            'name': "testqueue",
            'serializer': DummySerializer,
            'host': "localhost",
            'port': 6379,
            'db': 0}
        # Instantiate the HotQueue instance:
        self.queue = HotQueue(**kwargs)
        # Ensure that the properties of the instance are as expected:
        self.assertEqual(self.queue.name, kwargs['name'])
        self.assertEqual(self.queue.key, "hotqueue:%s" % kwargs['name'])
        self.assertEqual(self.queue.serializer, kwargs['serializer'])
        self.assertEqual(self.queue._HotQueue__redis.host, kwargs['host'])
        self.assertEqual(self.queue._HotQueue__redis.host, kwargs['host'])
        self.assertEqual(self.queue._HotQueue__redis.port, kwargs['port'])
        self.assertEqual(self.queue._HotQueue__redis.db, kwargs['db'])
        # Instantiate a HotQueue instance with only the required args:
        self.queue = HotQueue(kwargs['name'])
        # Ensure that the properties of the instance are as expected:
        self.assertEqual(self.queue.name, kwargs['name'])
        self.assertEqual(self.queue.key, "hotqueue:%s" % kwargs['name'])
        self.assertTrue(self.queue.serializer is pickle) # Defaults to cPickle or
                                                     # pickle, depending on the
                                                     # platform.
    
    def test_consume(self):
        """Test the consume generator method."""
        nums = [1, 2, 3, 4, 5, 6, 7, 8]
        # Test blocking with timeout:
        self.queue.put(*nums)
        msgs = []
        for msg in self.queue.consume(timeout=1):
            msgs.append(msg)
        self.assertEquals(msgs, nums)
        # Test non-blocking:
        self.queue.put(*nums)
        msgs = []
        for msg in self.queue.consume(block=False):
            msgs.append(msg)
        self.assertEquals(msgs, nums)
    
    def test_cleared(self):
        """Test for correct behaviour if the Redis list does not exist."""
        self.assertEquals(len(self.queue), 0)
        self.assertEquals(self.queue.get(), None)
    
    def test_get_order(self):
        """Test that messages are get in the same order they are put."""
        alphabet = ['abc', 'def', 'ghi', 'jkl', 'mno']
        self.queue.put(alphabet[0], alphabet[1], alphabet[2])
        self.queue.put(alphabet[3])
        self.queue.put(alphabet[4])
        msgs = []
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        self.assertEquals(msgs, alphabet)
    
    def test_length(self):
        """Test that the length of a queue is returned correctly."""
        self.queue.put('a message')
        self.queue.put('another message')
        self.assertEquals(len(self.queue), 2)
    
    def test_worker(self):
        """Test the worker decorator."""
        colors = ['blue', 'green', 'red', 'pink', 'black']
        # Test blocking with timeout:
        self.queue.put(*colors)
        msgs = []
        @self.queue.worker(timeout=1)
        def appender(msg):
            msgs.append(msg)
        appender()
        self.assertEqual(msgs, colors)
        # Test non-blocking:
        self.queue.put(*colors)
        msgs = []
        @self.queue.worker(block=False)
        def appender(msg):
            msgs.append(msg)
        appender()
        self.assertEqual(msgs, colors)
    
#.........这里部分代码省略.........
开发者ID:mgunneras,项目名称:hotqueue,代码行数:103,代码来源:tests.py

示例8: JukeboxUI

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
class JukeboxUI(cmd.Cmd, threading.Thread):

	prompt = "jukebox> "
	
	def __init__(self, jukebox):
		cmd.Cmd.__init__(self)
		threading.Thread.__init__(self)
		self.jukebox = jukebox
		self.playlist = None
		self.track = None
		self.results = False
		
		self.queue_play = HotQueue("wekkie:play")
	
	def run(self):
		container_loaded.wait()
		container_loaded.clear()
		
		print "Starting consume loop..."
		for uri in self.queue_play.consume():
			if uri:
				print "Try to play", uri
				link = Link.from_string(uri)
				if link.type() == Link.LINK_TRACK:
					self.jukebox.load_track(link.as_track())
					self.jukebox.play()
				elif link.type() == Link.LINK_ARTIST:
					browser = ArtistBrowser(link.as_artist())
					while not browser.is_loaded():
						time.sleep(0.1)
					toptracks = browser.tophit_tracks()
					print toptracks
					#random.shuffle(toptracks)					
					track = choice(toptracks)
					self.jukebox.load_track(track)
					self.jukebox.play()
				elif link.type() == 7: #Link.LINK_PLAYLIST:
					playlist = self.jukebox.starred
					track = choice(playlist)

					while track.availability() != 1:
						track = choice(playlist)

					self.jukebox.load_track(track)
					self.jukebox.play()
					
			else:
				self.jukebox.stop()
				
		try:
			self.cmdloop()
		finally:
			self.do_quit(None)

	def do_logout(self, line):
		self.jukebox.session.logout()

	def do_quit(self, line):
		self.jukebox.stop()
		self.jukebox.disconnect()
		print "Goodbye!"
		return True

	def do_list(self, line):
		""" List the playlists, or the contents of a playlist """
		if not line:
			for i, p in enumerate(self.jukebox.ctr):
				if p.is_loaded():
					print "%3d %s" % (i, p.name())
				else:
					print "%3d %s" % (i, "loading...")
			print "%3d Starred tracks" % (i + 1,)

		else:
			try:
				p = int(line)
			except ValueError:
				print "that's not a number!"
				return
			if p < 0 or p > len(self.jukebox.ctr):
				print "That's out of range!"
				return
			print "Listing playlist #%d" % p
			if p < len(self.jukebox.ctr):
				playlist = self.jukebox.ctr[p]
			else:
				playlist = self.jukebox.starred
			for i, t in enumerate(playlist):
				if t.is_loaded():
					print "%3d %s - %s [%s]" % (
						i, t.artists()[0].name(), t.name(),
						self.pretty_duration(t.duration()))
				else:
					print "%3d %s" % (i, "loading...")

	def pretty_duration(self, milliseconds):
		seconds = milliseconds // 1000
		minutes = seconds // 60
		seconds = seconds % 60
		duration = '%02d:%02d' % (minutes, seconds)
#.........这里部分代码省略.........
开发者ID:bertspaan,项目名称:wekkie,代码行数:103,代码来源:wekkie_player.py

示例9: read_job

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
        r.set(jobkey + ':fail_message', log['msg'])

    if cmd == 'log' or cmd == 'exception':
        logkey = 'log:%s' % uid
        if not r.keys(logkey):
            r.set(logkey, 1)
            lidx = 1
        else:
            lidx = r.incr(logkey)
        logkeytxt = logkey + ':%d' % lidx
        if cmd == 'log':
            r.set(logkeytxt, log['line'])
        else:
            r.set(logkeytxt, log['msg'])

    if cmd == 'exception':
        job = read_job(uid)
        if job:
            job.notify()


if __name__ == '__main__':
    while True:
        # trigger a purge every hour
        qlog.put({'cmd': 'purge'})
        for log in qlog.consume(timeout=3600):
            loop_handle(log)
        # sleep only 1 second if we keep asking break
        sleep(1)

开发者ID:chrmorais,项目名称:p4a-cloud,代码行数:31,代码来源:pollqlog.py

示例10: HotQueueTestCase

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
class HotQueueTestCase(unittest.TestCase):
    
    def setUp(self):
        """Create the queue instance before the test."""
        self.queue = HotQueue('testqueue')
    
    def tearDown(self):
        """Clear the queue after the test."""
        self.queue.clear()
    
    def test_arguments(self):
        """Test that HotQueue.__init__ accepts arguments correctly, and that
        the Redis key is correctly formed.
        """
        kwargs = {
            'name': "testqueue",
            'serializer': DummySerializer,
            'host': "localhost",
            'port': 6379,
            'db': 0}
        # Instantiate the HotQueue instance:
        self.queue = HotQueue(**kwargs)
        # Ensure that the properties of the instance are as expected:
        self.assertEqual(self.queue.name, kwargs['name'])
        self.assertEqual(self.queue.key, "hotqueue:%s" % kwargs['name'])
        self.assertEqual(self.queue.serializer, kwargs['serializer'])
        # Instantiate a HotQueue instance with only the required args:
        self.queue = HotQueue(kwargs['name'])
        # Ensure that the properties of the instance are as expected:
        self.assertEqual(self.queue.name, kwargs['name'])
        self.assertEqual(self.queue.key, "hotqueue:%s" % kwargs['name'])
        self.assertTrue(self.queue.serializer is pickle) # Defaults to cPickle
                                                         # or pickle, depending
                                                         # on the platform.
    
    def test_consume(self):
        """Test the consume generator method."""
        nums = [1, 2, 3, 4, 5, 6, 7, 8]
        # Test blocking with timeout:
        nums_added = self.queue.put(*nums)
        msgs = []
        for msg in self.queue.consume(timeout=1):
            msgs.append(msg)
        self.assertEqual(msgs, nums_added)
        for msg in msgs:
            self.queue.ack(msg.get_reservationId())
        # Test non-blocking:
        nums_added = self.queue.put(*nums)
        msgs = []
        for msg in self.queue.consume(block=False):
            msgs.append(msg)
        self.assertEqual(msgs, nums_added)
        for msg in msgs:
            self.queue.ack(msg.get_reservationId())

    def test_nack(self):
        """Test the consume generator method."""
        nums_added = self.queue.put("1")
        msg = self.queue.get() #1
        self.assertEqual(msg, nums_added[0])
        self.queue.nack(msg.get_reservationId())
        msg = self.queue.get() #2
        self.assertEqual(msg, nums_added[0])
        self.queue.nack(msg.get_reservationId())
        msg = self.queue.get() #3
        if msg:
            self.assertEqual(msg, nums_added[0])
            self.queue.ack(msg.get_reservationId())
        self.assertEqual(msg, nums_added[0])
        self.assertEqual(len(self.queue), 0)
        self.assertEqual(msg.get_deliveryCount(),3) #3
    
    def test_cleared(self):
        """Test for correct behaviour if the Redis list does not exist."""
        self.assertEqual(len(self.queue), 0)
        self.assertEqual(self.queue.get(), None)
    
    def test_get_order(self):
        """Test that messages are get in the same order they are put."""
        alphabet = ['abc', 'def', 'ghi', 'jkl', 'mno']
        msg_added = []
        msg_added.extend(self.queue.put(alphabet[0], alphabet[1], alphabet[2]))
        msg_added.extend(self.queue.put(alphabet[3]))
        msg_added.extend(self.queue.put(alphabet[4]))
        msgs = []
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        self.assertEqual(msgs, msg_added)
        for msg in msgs:
            self.queue.ack(msg.get_reservationId())

    def test_length(self):
        """Test that the length of a queue is returned correctly."""
        self.queue.put('a message')
        self.queue.put('another message')
        self.assertEqual(len(self.queue), 2)
    
#.........这里部分代码省略.........
开发者ID:lovato,项目名称:hotqueue,代码行数:103,代码来源:tests.py

示例11: int

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
# Connect on Mosquitto
mqttc.connect("52.33.59.166", 1883,60)
# Continue the network loop
mqttc.loop_start()
print "Started"

while True:
	
	if HVAC== "ON":
		GPIO.output(HVAC_RUN, GPIO.HIGH)
		GPIO.output(HVAC_STANDBY, GPIO.LOW)
	else:
		GPIO.output(HVAC_RUN, GPIO.LOW)
		GPIO.output(HVAC_STANDBY, GPIO.HIGH)

	for item in queue.consume():
		print item
                if item[0:1] == "4" and HVAC == "OFF":
                    continue
                if item[1:2] == "1":
                    temperatureData['teamId'] = item[0:1]
                    temperatureData['type'] = "temperature"
                    temperatureData['tval'] = int(item[2:4])
                    temperatureData['time'] = str(datetime.now())
                    tempJsonData = json.dumps(temperatureData)
                    mqttc.publish("TemperatureRT", tempJsonData)

                if item[1:2] == "2":
                    humidityData['teamId'] = item[0:1]
                    humidityData['type'] = "humidity"
                    humidityData['hval'] = int(item[2:4])
开发者ID:DhruvKalaria,项目名称:NEST-IntelligentThermostat,代码行数:33,代码来源:thermostat.py

示例12: HotQueueTestCase

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
class HotQueueTestCase(unittest.TestCase):
    def setUp(self):
        """Create the queue instance before the test."""
        self.queue = HotQueue("testqueue")

    def tearDown(self):
        """Clear the queue after the test."""
        self.queue.clear()

    def test_arguments(self):
        """Test that HotQueue.__init__ accepts arguments correctly, and that
        the Redis key is correctly formed.
        """
        kwargs = {"name": "testqueue", "serializer": DummySerializer, "host": "localhost", "port": 6379, "db": 0}
        # Instantiate the HotQueue instance:
        self.queue = HotQueue(**kwargs)
        # Ensure that the properties of the instance are as expected:
        self.assertEqual(self.queue.name, kwargs["name"])
        self.assertEqual(self.queue.key, "hotqueue:%s" % kwargs["name"])
        self.assertEqual(self.queue.serializer, kwargs["serializer"])
        self.assertEqual(self.queue._HotQueue__redis.host, kwargs["host"])
        self.assertEqual(self.queue._HotQueue__redis.host, kwargs["host"])
        self.assertEqual(self.queue._HotQueue__redis.port, kwargs["port"])
        self.assertEqual(self.queue._HotQueue__redis.db, kwargs["db"])
        # Instantiate a HotQueue instance with only the required args:
        self.queue = HotQueue(kwargs["name"])
        # Ensure that the properties of the instance are as expected:
        self.assertEqual(self.queue.name, kwargs["name"])
        self.assertEqual(self.queue.key, "hotqueue:%s" % kwargs["name"])
        self.assertTrue(self.queue.serializer is pickle)  # Defaults to cPickle
        # or pickle, depending
        # on the platform.

    def test_consume(self):
        """Test the consume generator method."""
        nums = [1, 2, 3, 4, 5, 6, 7, 8]
        # Test blocking with timeout:
        self.queue.put(*nums)
        msgs = []
        for msg in self.queue.consume(timeout=1):
            msgs.append(msg)
        self.assertEqual(msgs, nums)
        # Test non-blocking:
        self.queue.put(*nums)
        msgs = []
        for msg in self.queue.consume(block=False):
            msgs.append(msg)
        self.assertEqual(msgs, nums)

    def test_cleared(self):
        """Test for correct behaviour if the Redis list does not exist."""
        self.assertEqual(len(self.queue), 0)
        self.assertEqual(self.queue.get(), None)

    def test_get_order(self):
        """Test that messages are get in the same order they are put."""
        alphabet = ["abc", "def", "ghi", "jkl", "mno"]
        self.queue.put(alphabet[0], alphabet[1], alphabet[2])
        self.queue.put(alphabet[3])
        self.queue.put(alphabet[4])
        msgs = []
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        self.assertEqual(msgs, alphabet)

    def test_length(self):
        """Test that the length of a queue is returned correctly."""
        self.queue.put("a message")
        self.queue.put("another message")
        self.assertEqual(len(self.queue), 2)

    def test_worker(self):
        """Test the worker decorator."""
        colors = ["blue", "green", "red", "pink", "black"]
        # Test blocking with timeout:
        self.queue.put(*colors)
        msgs = []

        @self.queue.worker(timeout=1)
        def appender(msg):
            msgs.append(msg)

        appender()
        self.assertEqual(msgs, colors)
        # Test non-blocking:
        self.queue.put(*colors)
        msgs = []

        @self.queue.worker(block=False)
        def appender(msg):
            msgs.append(msg)

        appender()
        self.assertEqual(msgs, colors)
        # Test decorating a class method:
        self.queue.put(*colors)
        msgs = []
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:hotqueue,代码行数:103,代码来源:tests.py

示例13: matchmyregex

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
REGM_uptime_sec = re.compile(r"log_uptime")
REGM_mcast = re.compile(r"mcast")
REGM_invalid = re.compile(r"invalid data received")

#extract this
REGEXupSec = re.compile(r"(S : \d+.\d+)")
REGEXupSecDetail = re.compile(r"(\d+)")
REGEXupMin = re.compile(r"(up \d+)")
REGEXupHourMin = re.compile(r"(up +\d+:\d+)")
REGEXupDays = re.compile(r"(up \d+ day)")
REGEXdatetimeSTB = re.compile(r"(\d+-\d+-\d+\s\d+:\d+:\d+)")
REGEXdatetimeServer = re.compile(r"(^\d{10})")
REGEXip = re.compile(r"(\d+\.\d+\.\d+\.\d+)")
REGEXmac = re.compile(r"([\dA-F]{2}:[\dA-F]{2}:[\dA-F]{2}:[\dA-F]{2}:[\dA-F]{2}:[\dA-F]{2})")
REGEXplayurl = re.compile(r"([\a-z]{3,4}://[A-Za-z0-9_\.-]+)")
REGEXdecodeerr = re.compile(r":\s\d+")
REGEXdecodeerrII = re.compile(r":\d+,")
REGEX_serial = re.compile(r"Serial")

##read redis:
if __name__ == "__main__":
    for line in queue.consume():
        lineClean = line.split('@')[1]
        lineNo = line.split('@')[0]
        try:
            matchmyregex(lineClean)
        except:
            print lineClean
            print traceback.format_exc()
            pass
开发者ID:feijilei,项目名称:beewatch,代码行数:32,代码来源:parse_airties_logs.py

示例14: status

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
                count -= 1
                status(job, "Upload failed (%d remaining)" % count)
                if not count:
                    raise
                sleep(5)
                continue

            r.raise_for_status()
            break

    status(job, "Done")


# === go !
print "== Ready to build!"
for task in qjob.consume():
    uid = task["uid"]
    try:
        id_status = 0
        max_status = base_maxstatus
        status(task, "Initialize job")
        # create a directory
        job_dir = realpath(join(root_dir, uid))
        mkdir(job_dir)
        qlog.put({"cmd": "start", "uid": uid})
        builder(job_dir, **task)
        qlog.put({"cmd": "done", "uid": uid})
    except Exception, e:
        print "Got exception", e
        import traceback
开发者ID:brousch,项目名称:p4a-cloud,代码行数:32,代码来源:builder.py

示例15: HotQueueTestCase

# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import consume [as 别名]
class HotQueueTestCase(unittest.TestCase):
    
    def setUp(self):
        """Create the queue instance before the test."""
        self.queue = HotQueue('testqueue')
    
    def tearDown(self):
        """Clear the queue after the test."""
        self.queue.clear()
    
    def test_consume(self):
        """Test the consume generator method."""
        nums = [1, 2, 3, 4, 5, 6, 7, 8]
        # Test blocking with timeout:
        self.queue.put(*nums)
        msgs = []
        for msg in self.queue.consume(timeout=1):
            msgs.append(msg)
        self.assertEquals(msgs, nums)
        # Test non-blocking:
        self.queue.put(*nums)
        msgs = []
        for msg in self.queue.consume(block=False):
            msgs.append(msg)
        self.assertEquals(msgs, nums)
    
    def test_cleared(self):
        """Test for correct behaviour if the Redis list does not exist."""
        self.assertEquals(len(self.queue), 0)
        self.assertEquals(self.queue.get(), None)
    
    def test_get_order(self):
        """Test that messages are get in the same order they are put."""
        alphabet = ['abc', 'def', 'ghi', 'jkl', 'mno']
        self.queue.put(alphabet[0], alphabet[1], alphabet[2])
        self.queue.put(alphabet[3])
        self.queue.put(alphabet[4])
        msgs = []
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        msgs.append(self.queue.get())
        self.assertEquals(msgs, alphabet)
    
    def test_length(self):
        """Test that the length of a queue is returned correctly."""
        self.queue.put('a message')
        self.queue.put('another message')
        self.assertEquals(len(self.queue), 2)
    
    def test_worker(self):
        """Test the worker decorator."""
        colors = ['blue', 'green', 'red', 'pink', 'black']
        # Test blocking with timeout:
        self.queue.put(*colors)
        msgs = []
        @self.queue.worker(timeout=1)
        def appender(msg):
            msgs.append(msg)
        appender()
        self.assertEqual(msgs, colors)
        # Test non-blocking:
        self.queue.put(*colors)
        msgs = []
        @self.queue.worker(block=False)
        def appender(msg):
            msgs.append(msg)
        appender()
        self.assertEqual(msgs, colors)
    
    def test_threaded(self):
        """Threaded test of put and consume methods."""
        msgs = []
        def put():
            for num in range(3):
                self.queue.put('message %d' % num)
                sleep(0.1)
        def consume():
            for msg in self.queue.consume(timeout=1):
                msgs.append(msg)
        putter = threading.Thread(target=put)
        consumer = threading.Thread(target=consume)
        putter.start()
        consumer.start()
        for thread in [putter, consumer]:
            thread.join()
        self.assertEqual(msgs, ['message 0', 'message 1', 'message 2'])
开发者ID:zacharyvoase,项目名称:hotqueue,代码行数:90,代码来源:tests.py


注:本文中的hotqueue.HotQueue.consume方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。