From cd1072f2aa51157112a9d210f7144cec5a762171 Mon Sep 17 00:00:00 2001 From: ngharo Date: Fri, 29 Jun 2018 23:37:52 -0500 Subject: WIP --- shared.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 shared.py (limited to 'shared.py') diff --git a/shared.py b/shared.py new file mode 100644 index 0000000..3fe6a4c --- /dev/null +++ b/shared.py @@ -0,0 +1,59 @@ +import sys +import queue +import pydle +import logging +import time +from lib import worker + +num_worker_threads = 2 +password = 'xxx' + +class ansibot(pydle.Client): + def on_connect(self): + self.join('#test99') + + def on_message(self, source, target, message): + if message != "!spam": + return + + global dispatched + global q + + """ + Here I thought I could have one client pickup and dispatch + work onto a queue. + + Clients then pick items off the queue send it along as a message to + the channel. + + What happens is the first client gobbles up the entire queue. I'm thinking + that client on_message callbacks are dispatched in serial. Am i right? + + This kinda thing works in testing using threading in place of ClientPool(). + Any pointers? + """ + if not dispatched: + dispatched = True + # generate some some data to push on the queue + [q.put(str(x)) for x in range(10)] + + # go to work on data + while not q.empty(): + part = q.get() + + self.message(source, part) + # give time for another client to grab items off the queue + # (theoretically) + time.sleep(0.1) + q.task_done() + +q = queue.Queue() +dispatched = False + +pool = pydle.ClientPool() +for i in range(num_worker_threads): + client = ansibot('zz' + str(i)) + pool.connect(client, 'irc.foo.bar', 7001, password=password, tls=True, tls_verify=False) + +# This will make sure all clients are treated in a fair way priority-wise. +pool.handle_forever() -- cgit v1.2.3