[Twisted-Python] Newbie question - simpleclient.py crashes

Frank Millman frank at chagford.com
Sun Oct 30 02:50:31 EST 2005


Hi all,

I have just started looking at Twisted. I thought I would start by working
my way through the examples. The first one I tried crashed on me! I can
patch it to get it to work, but I would rather learn the exact reason for
the crash, and the correct way to fix it.

I am trying to run simpleserver.py and simpleclient.py, using RH9, Python
2.4.1, and Twisted 2.1.0. I start simpleserver from tty1, and then from tty2
I run simpleclient. This is the result (shortened) -

Server said: hello, world!
connection lost
Connection lost - goodbye!
Traceback:
  [...]
  File '.../twisted/internet/base.py', line 398, in _continueSystemEvent
    for callList in sysEvtTriggers[1], sysEvtTriggers[2]:
  exceptions.TypeError: unsubscriptable object

AFAICT, this is what is happening.

simpleclient calls reactor.stop() from a number of places, but for this
exercise it calls it twice - once from EchoClient.connectionLost(), once
from EchoFactory.clientConnectionLost(). The first time,
base._continueSystemEvent() is called with eventType "shutdown". It handles
the event, then deletes "shutdown" from self._eventTriggers. When it is
called the second time, also with eventType "shutdown", it cannot find the
event type as it has been deleted, so it crashes with the above traceback.

I changed simpleclient.EchoClient.connectionLost() so that it does not call
reactor.stop(), and the program runs without errors. Is this the correct
solution? Why do the Protocol and the Factory both have a connectionLost
method? Which one should call reactor.stop()?

Thanks.

Frank Millman





More information about the Twisted-Python mailing list