小编Cod*_*oid的帖子

线程轮询 sqs 并将其添加到 python 队列中以处理模具

我有一段多线程代码 - 3 个线程,用于从 SQS 轮询数据并将其添加到 python 队列中。5 个线程从 python 队列中获取消息,处理它们并将其发送到后端系统。

这是代码:

python_queue = Queue.Queue()

class GetDataFromSQS(threading.Thread):
    """Threaded Url Grab"""
    def __init__(self, python_queue):
        threading.Thread.__init__(self)
        self.python_queue = python_queue

    def run(self):
        while True:
            time.sleep(0.5) //sleep for a few secs before querying again
            try:
                msgs = sqs_queue.get_messages(10)
                if msgs == None:
                    print "sqs is empty now"!
                for msg in msgs:
                    #place each message block from sqs into python queue for processing
                    self.python_queue.put(msg)
                    print "Adding a new message to Queue. Queue size is now …
Run Code Online (Sandbox Code Playgroud)

python queue multithreading amazon-sqs

6
推荐指数
1
解决办法
3607
查看次数

标签 统计

amazon-sqs ×1

multithreading ×1

python ×1

queue ×1