I am trying to feed both an event and a queue to my worker threads. The queue is for them to talk to each other the event is for signalling them to stop working when needed. I keep getting this error and I cant quite figure out what is wrong with my definition constructors
Here is the error:
Traceback (most recent call last):
File "dualThreaded.py", line 52, in <module>
c = get_Count(q, e)
TypeError: __init__() takes exactly 2 arguments (3 given)
Here is my code:
from Queue import Empty
from multiprocessing import Process, Queue, Event
import time
class get_Count(object):
def __init__(self, q):
self.q = q
def run(self, e):
i = 0
run = True
while run == True:
print 'putting'
self.q.put('foo %d' % i )
time.sleep(.5)
if e.is_set():
run = False
class read_Count(object):
def __init__(self, q):
self.q = q
def run(self, e):
while True:
try:
value = self.q.get(False)
print value
except Empty:
print 'Nothing to process atm'
e.set()
time.sleep(.2)
if __name__ == '__main__':
e = Event()
q = Queue()
c = get_Count(q, e)
l = read_Count(q, e)
p1 = Process(target=c.run)
p1.start()
p2 = Process(target=l.run)
p2.start()
p1.join()
p2.join()
edit fixed typos: