[Twisted-Python] Twisted with callInThread

Mike Zupan hijinks at gmail.com
Tue Nov 2 16:11:06 EDT 2010

I stripped down my app but this should give you an example of what i'm doing

def run_app(f):
    p = Popen(['/usr/bin/app'],stdout=PIPE)
    while True:
        o = p.stdout.readline()
        if o == '' and p.poll() != None: break

        reactor.callFromThread(f, o)

class Echo(Protocol):
    def connectionMade(self):

        reactor.callInThread(run_app, self.appDataReceived)

    def dataReceived(self, data):
        data = data.strip()
        if data == "getmore":
            print "getmore"

    def appDataReceived(self, u):
        print u

def main():
    factory = Factory()
    factory.protocol = Echo
    reactor.listenTCP(3646, factory)

if __name__ == "__main__":

I have an app which I want to connect in and run a app that
continually spits out data to stdout. Right now my app works but the
issue is when the client exits the socket connection the /usr/bin/app
still continues to run. The more socket connections made the more this
app is still running.

Is there anyway from the Echo Procool to kill the run_app() function?

More information about the Twisted-Python mailing list