1

I'm making a threaded chat server and I need a way to send a message to all the clients. I could use a global queue but then only one of the threads handling the clients would be able to send the message. So I was wondering if its possible to create a separate queue object within each of the client threads and append them to a list so that I would be able to send the message to each client's queue. Is this possible?

clientqueues = [] #Global list of client queues class ClientThread(threading.Thread): def __init__(self): myqueue = Queue.Queue() #Client queue clientqueues.append(myqueue) ... def MessageAllClients(message): global clientqueues for queue in clientqueues: queue.put(message) 

Would this work or am I going about this the wrong way?

2 Answers 2

3

Your approach is just fine. The only thing I would change is making clientqueues a static member of ClientThread rather than a global variable.

Sign up to request clarification or add additional context in comments.

1 Comment

Well thats great news I'm not thinking crazy after all. Thank you for the quick response!
0

A Queue is just an object (like everything in Python), so no problem with making a list of them.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.