import threading
import Queue
NUM_THREADS = 2 # you can change this if you want
semaphore = threading.Semaphore(NUM_THREADS)
threads = NUM_THREADS
running_threads = []
lock = threading.Lock()
q = Queue.Queue()
# moved the check function out of the loop
def check(name, q, s):
# acquire the semaphore
with s:
not_empty = True
while not_empty:
try:
email = q.get(False) # we are passing false so it won't block.
except Queue.Empty, e:
not_empty = False
break
lock.acquire()
print email, name, threading.active_count()
lock.release()
# additional work ...
q.task_done()
for x in open(names):
name = x.strip()
for word in open(emails):
q.put(word.strip())
for i in range(th