[Twisted-Python] help! - listenTCP failing

Hi, I'm building an app that will need the ability to start and stop protocol servers dynamically. As part of figuring this out, I've added an ApplicationService to the app, and within ApplicationService.startService(), I'm calling self.get_application.listenTCP(portnum, myprotocol). This is having no visible effect, since the port is not getting opened. I tried, within startService(), calling reactor.listenTCP() instead. This starts up the protocol and opens the port just fine, but when I later call app.unlistenTCP(port) to shut down the protocol, I get the exception (see below). What am I doing wrong? What's the best and simplest way to dynamically start and stop server protocols at runtime()? Thanks in advance David Traceback (most recent call last): File "/usr/lib/python2.2/site-packages/twisted/internet/app.py", line 744, in run main.run(installSignalHandlers=installSignalHandlers) File "/usr/lib/python2.2/site-packages/twisted/internet/main.py", line 106, in run _getReactor().run() File "/usr/lib/python2.2/site-packages/twisted/internet/default.py", line 113, in run self.mainLoop() File "/usr/lib/python2.2/site-packages/twisted/internet/default.py", line 124, in mainLoop self.doIteration(t) --- <exception caught here> --- File "/usr/lib/python2.2/site-packages/twisted/internet/default.py", line 450, in doSelect why = getattr(selectable, method)() File "/usr/lib/python2.2/site-packages/twisted/internet/tcp.py", line 105, in doRead return self.protocol.dataReceived(data) File "/usr/lib/python2.2/site-packages/twisted/protocols/telnet.py", line 314, in dataReceived why = self.processChunk(c) File "/usr/lib/python2.2/site-packages/twisted/protocols/telnet.py", line 261, in processChunk self.processLine(buf) File "/usr/lib/python2.2/site-packages/twisted/protocols/telnet.py", line 221, in processLine self.mode = getattr(self, "telnet_"+self.mode)(line) File "/usr/lib/python2.2/site-packages/twisted/protocols/telnet.py", line 237, in telnet_Password if not self.checkUserAndPass(self.username, paswd): File "mytelnetd.py", line 34, in checkUserAndPass self.factory.appl.killTelnet() File "mytelnetd.py", line 61, in killTelnet self.unlistenTCP(2000) File "/usr/lib/python2.2/site-packages/twisted/internet/app.py", line 444, in unlistenTCP if self._listenerDict.has_key((port_, interface_)): exceptions.UnboundLocalError: local variable 'port_' referenced before assignment

On Wed, Mar 26, 2003 at 04:32:11PM +1200, David McNab wrote:
It seems as though reactor.listenTCP() is never being invoked. The traceback you got below is a result of this. I've fixed it in CVS so that it raises twisted.internet.error.NotListeningError now, instead of a confusing UnboundLocalError. Why reactor.listenTCP() isn't being invoked is unclear. You might try adding some debug prints to the critical portions of the code, or stepping through it with pdb. If you are still stuck after some attempts, post a little code (keyword: little) that demonstrates the problem, so a developer can easily duplicate and then fix it. Jp -- "There is no reason for any individual to have a computer in their home." -- Ken Olson, President of DEC, World Future Society Convention, 1977 -- up 6 days, 21:59, 4 users, load average: 0.52, 0.41, 0.19

On 26 Mar 2003 16:32:11 +1200 David McNab <david@rebirthing.co.nz> wrote:
You probably want to do this on the reactor anyway, since these are not "persistent" servers, as it were. That being said, this is a bug in Twisted - I fixed it in CVS, hopefully. -- Itamar Shtull-Trauring http://itamarst.org/ http://www.zoteca.com -- Python & Twisted consulting

On Wed, Mar 26, 2003 at 04:32:11PM +1200, David McNab wrote:
It seems as though reactor.listenTCP() is never being invoked. The traceback you got below is a result of this. I've fixed it in CVS so that it raises twisted.internet.error.NotListeningError now, instead of a confusing UnboundLocalError. Why reactor.listenTCP() isn't being invoked is unclear. You might try adding some debug prints to the critical portions of the code, or stepping through it with pdb. If you are still stuck after some attempts, post a little code (keyword: little) that demonstrates the problem, so a developer can easily duplicate and then fix it. Jp -- "There is no reason for any individual to have a computer in their home." -- Ken Olson, President of DEC, World Future Society Convention, 1977 -- up 6 days, 21:59, 4 users, load average: 0.52, 0.41, 0.19

On 26 Mar 2003 16:32:11 +1200 David McNab <david@rebirthing.co.nz> wrote:
You probably want to do this on the reactor anyway, since these are not "persistent" servers, as it were. That being said, this is a bug in Twisted - I fixed it in CVS, hopefully. -- Itamar Shtull-Trauring http://itamarst.org/ http://www.zoteca.com -- Python & Twisted consulting
participants (3)
-
David McNab
-
Itamar Shtull-Trauring
-
Jp Calderone