Hi
> I'm willing to implement timeouts to connexion using python twisted
> thrift. I mean: if a connexion is inactive for some amount of time,
> close it, and clean/release associated objects.
>
> There is already support for that in twisted, so it's quite simple, it
> looks like:
>
> # subclass ThriftServerProtocol to override connectionLost method
> class MyTxThriftServerProtocol(TTwisted.ThriftServerProtocol):
> def connectionLost(self, reason):
> # clean pending sessions on this connexion
> self.factory.processor._handler.do_something_to_clean()
I wouldn't use the handler for this stuff, though. IMHO it should belong in
the factory, and make the handler protocol-independent. For example:
class MyTxThriftServerProtocol(TTwisted.ThriftServerProtocol):
def connectionLost(self, reason):
# clean pending sessions on this connexion
self.factory.do_something_to_clean(self)
> Is there a way to get the Protocol instance when a method of a thrift
> service handler is called?
If you still want to use your handler for cleaning up pending connections, you
can do this:
# subclass ThriftServerProtocol to override connectionLost method
class MyTxThriftServerProtocol(TTwisted.ThriftServerProtocol):
def connectionLost(self, reason):
# clean pending sessions on this connexion
self.factory.processor._handler.do_something_to_clean(self)
and change do_something_to_clean take an additional argument (a protocol
instance in this case). The problem is that you cannot declare
do_something_to_clean in the Thrift service definition, since there's no
Thrift representation of what's a protocol (and shouldn't). That's why I think
moving all this stuff to the factory would make your code cleaner, separating
concerns (handler, protocol, transport, etc.)
Cheers.