Skip to content

Instantly share code, notes, and snippets.

@DingGGu
Last active August 29, 2017 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DingGGu/3b7e51b53ff58f6306cbbb2a1a1b1538 to your computer and use it in GitHub Desktop.
Save DingGGu/3b7e51b53ff58f6306cbbb2a1a1b1538 to your computer and use it in GitHub Desktop.
python sqs multithread
from threading import Thread
from Queue import Queue
import boto.sqs
from boto.sqs.message import RawMessage
sqs = boto.sqs.connect_to_region('ap-northeast-1')
queue = sqs.get_queue('queue-name')
q = Queue()
for i in user_id_list:
q.put(i)
THREADS = 20
def doWork(q):
while True:
user_id = q.get()
if user_id is None:
break
msg = RawMessage()
msg.set_body(json.dumps({
'target': user_id,
}))
queue.write(msg)
for i in range(THREADS):
t = Thread(target=doWork, args=(q, ))
q.put(None) # for stop while
t.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment