[Twisted-Python] 9.0.0 question

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Fri Jan 22 16:40:38 EST 2010

On 21 Jan, 03:30 pm, termim at gmail.com wrote:
>On Thu, Jan 21, 2010 at 3:58 AM,  <exarkun at twistedmatrix.com> wrote:
>>On 03:43 am, glyph at twistedmatrix.com wrote:
>>>On Jan 20, 2010, at 3:20 PM, Mikhail Terekhov wrote:
>>>>I've switched recently from 8.2 to 9.0 and noticed that some of my
>>>>client scripts
>>>>hang in reactor.stop() on exit sometimes. That never happened 
>>>>example if I run the gethostbyname.py from the twisted-names 
>>>>it prints the correct result and hangs forever until I press 
>>>>Then it prints the
>>>>following traceback:
>>>I don't see the behavior you describe, but I do see this traceback on
>>>trunk with every 3rd run or so of that example - maybe the example is
>>>doc/names/examples$ python gethostbyname.py  twistedmatrix.com
>>>twisted/names/dns.py:1670: DeprecationWarning: Please only pass IPs 
>>>write(), not hostnames
>>> self.transport.write(message.toStr(), address)
>>>Traceback (most recent call last):
>>> File "twisted/internet/udp.py", line 121, in doRead
>>>   self.protocol.datagramReceived(data, addr)
>>> File "twisted/names/dns.py", line 1700, in datagramReceived
>>>   d.callback(m)
>>> File "twisted/internet/defer.py", line 239, in callback
>>>   self._startRunCallbacks(result)
>>> File "twisted/internet/defer.py", line 308, in _startRunCallbacks
>>>   self._runCallbacks()
>>>--- <exception caught here> ---
>>> File "twisted/internet/defer.py", line 324, in _runCallbacks
>>>   self.result = callback(self.result, *args, **kw)
>>> File "twisted/names/common.py", line 239, in <lambda>
>>>   ).addBoth(lambda passthrough: 
>>>exceptions.AttributeError: 'NoneType' object has no attribute
>I think I found it, it is somewhat different IMHO. When you run
>   python gethostbyname.py localhost
>notice the '''localhost''' there, the getHostByName('localhost') 
>defer.succeed(..) so the callback gotResult and hence reactor.stop()
>is called even before reactor is run and for some reason it hangs there
>inside reactor.stop().
>So there are actually two points here:
>1. the gethostbyname.py example should probably be changed something
>    like this

This sounds a lot like another example of the problem described in 
>2. Why reactor.stop() hangs if it is called before reactor.run()?

It doesn't.  It raises an exception.  The reason the example hangs is 
that since reactor.stop() was called before reactor.run(), it's not 
called *after* reactor.run().  So the reactor never stops.


More information about the Twisted-Python mailing list