remove reactor.iterate from dht shutdown

This commit is contained in:
Job Evers-Meltzer 2016-11-03 10:43:24 -05:00
parent fe7700d726
commit 693fef1964

View file

@ -21,6 +21,7 @@ import msgtypes
import msgformat import msgformat
from contact import Contact from contact import Contact
reactor = twisted.internet.reactor reactor = twisted.internet.reactor
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -143,7 +144,9 @@ class KademliaProtocol(protocol.DatagramProtocol):
del self._sentMessages[message.id] del self._sentMessages[message.id]
if hasattr(df, '_rpcRawResponse'): if hasattr(df, '_rpcRawResponse'):
# The RPC requested that the raw response message and originating address be returned; do not interpret it # The RPC requested that the raw response message
# and originating address be returned; do not
# interpret it
df.callback((message, address)) df.callback((message, address))
elif isinstance(message, msgtypes.ErrorMessage): elif isinstance(message, msgtypes.ErrorMessage):
# The RPC request raised a remote exception; raise it locally # The RPC request raised a remote exception; raise it locally
@ -301,19 +304,19 @@ class KademliaProtocol(protocol.DatagramProtocol):
df.errback(failure.Failure(TimeoutError(remoteContactID))) df.errback(failure.Failure(TimeoutError(remoteContactID)))
else: else:
# This should never be reached # This should never be reached
print "ERROR: deferred timed out, but is not present in sent messages list!" log.error("deferred timed out, but is not present in sent messages list!")
def stopProtocol(self): def stopProtocol(self):
""" Called when the transport is disconnected. """ Called when the transport is disconnected.
Will only be called once, after all ports are disconnected. Will only be called once, after all ports are disconnected.
""" """
log.info('Stopping dht')
for key in self._callLaterList.keys(): for key in self._callLaterList.keys():
try: try:
if key > time.time(): if key > time.time():
log.info('Cancelling %s', self._callLaterList[key])
self._callLaterList[key].cancel() self._callLaterList[key].cancel()
except Exception, e: except Exception, e:
print e log.exception('Failed to cancel %s', self._callLaterList[key])
del self._callLaterList[key] del self._callLaterList[key]
#TODO: test: do we really need the reactor.iterate() call?
reactor.iterate()