Hi,
I'm trying to write a python lib that will implement the client side of a certain chat protocol.
After i connect to the server i start the main loop where i read from the server and handle received commands and here i need to call a callback function (like on_message, or on file_received, etc).
How should i go about implementing this? Should a start a new thread for each callback function? As maybe some callbacks will take some time to return and i will timeout.
Also if the main loop where i read from the server is in a thread can i write to the socket from another thread(send messages to the server)?
Or is there a better approach?
Thanks.
views:
94answers:
3
+5
A:
For a python app doing this, I wouldn't use threads. I would use a framework like Twisted.
The docs have examples; here's a chat example.
Thomas Vander Stichele
2009-11-03 23:17:16
+1
A:
I would use the select module, or alternately twisted, however select is a bit more portable, and to my mind somewhat more pythonic.
Richo
2009-11-04 06:00:39