[Twisted-Python] twisted threading server has to be stopped with KILL
snacktime at gmail.com
Tue Feb 8 15:15:35 EST 2005
On Tue, 08 Feb 2005 15:06:18 -0500, Itamar Shtull-Trauring > > The
only place I call threads is through deferToThread, and the server
> > still hangs even after all the threads called with deferToThread have
> > run and their callbacks processed. What other threads could there be
> > that are blocking?
> In that case Twisted should exit correctly.
Here is the code. ProcessTransaction is the class (not shown here)
that contains the blocking method Do(). After playing with it some
more I found something interesting. Say I send a number of requests
with the client, then hit control-C on the server. The server won't
shutdown, but on the very next connection from the client the server
drops the connection immediately before the ssl handshake is
completed and shuts down. It seems like some sort of event loop where
the INT signal isn't getting processed until the next event happens,
which in this case would be the connection.
def dataReceived(self, data):
"""As soon as any data is received, process it in a thread."""
self.transport.write("%s\r\n" % data)
c = ProcessTransaction()
# Blocking function called here in thread
d = threads.deferToThread(c.Do,data)
application = service.Application("otransact")
OTService = service.IServiceCollection(application)
OTfactory = Factory()
OTfactory.protocol = OT
OTServer = internet.SSLServer(8000, OTfactory,ServerContextFactory())
More information about the Twisted-Python