[Tutor] A chat server in Python

Scot W. Stevenson scot@possum.in-berlin.de
Mon, 12 Aug 2002 10:55:43 +0200


Hello Danny, 

> I've started to write a chat server in Python!  It's in preparation for
> writing the online network part of that dots-and-boxes project that I
> forgot about last month.  *grin*

Thank you for the code example! If I could bother you with a few 
questions...

============================
from threading import *
============================

The docs for the threading module say that it is safe to do this, but I 
remember being told by one of the books (can't find the reference right 
now, will dig if important) not to unless you're importing Tkinter. Is 
threading another exception, or has "from <module> import *" become less 
dangerous in Python 2.2, or was the original warning overdone?

============================
    def _waitForShutdownOrNewMessages(self):
        return self._events.get()
============================

Is ease of maintainance the the reason not to put self._events.get() 
directly into the "while 1" loop? 

============================
       self._listeners_lock.acquire()
       try:
            listeners_copy = self._listeners[:]
        finally:
            self._listeners_lock.release()
        for listener in listeners_copy:
            self._tryToSendMessageToListener(msg, listener)
============================

I'm not sure I understand the reason for the copy of self._listeners, or in 
other words, why this part isn't simply

---------------------------------------------------
self._listeners_lock.acquire()
try: 
    for listener in self._listeners:
        self._tryToSendMessageToListener(msg, listener)
finally:
    self._listeners_lock.release()
----------------------------------------------------

since if self._listeners() is empty, the for-loop wouldn't run, and I don't 
see anything that could change self._listeners.

Thank you again,
Y, Scot

-- 
  9:59am  up 55 days,  7:21,  2 users,  load average: 0.00, 0.07, 0.08