aboutsummaryrefslogtreecommitdiff
path: root/shared.py
diff options
context:
space:
mode:
Diffstat (limited to 'shared.py')
-rw-r--r--shared.py59
1 files changed, 59 insertions, 0 deletions
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()