[Twisted-Python] Twisted with callInThread
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) reactor.run() if __name__ == "__main__": 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?
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?
Instead of using run_app (which I assume is in run in a thread?), using reactor.spawnProcess will let you have the process management integrated with Twisted: http://twistedmatrix.com/documents/current/core/howto/process.html
participants (2)
-
Itamar Turner-Trauring
-
Mike Zupan