blob: 3fe6a4c48ee9cfb77679232c32d376771eb8bed9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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()
|