code: def _stopHeartbeatWithReason(self, reason=DISCONNECT.GO_AWAY):
          '''We lost our connection - stop our heartbeat.  This runs when the
          protocol wants a disconnection.
  
          This redundant output ensures that the heartbeater stops
          immediately after the connection is lost.  Twisted will call
          connectionLost after loseConnection, but between the two the
          heartbeat-writing callback may run, after the transport's been
          lost.  Relying on connectionLost to cancel our
          callback thus creates a race condition.
  
          '''
          self.heartbeater.stop()
          self.heartbeater = Nonf _stopHeartbeatWithReason(self, reason=DISCONNECT.GO_AWAY):
          '''We lost our connection - stop our heartbeat.  This runs when the
          protocol wants a disconnection.
  
          This redundant output ensures that the heartbeater stops
          immediately after the connection is lost.  Twisted will call
          connectionLost after loseConnection, but between the two the
          heartbeat-writing callback may run, after the transport's been
          lost.  Relying on connectionLost to cancel our
          callback thus creates a race condition.
  
          '''
          self.heartbeater.stop()
          self.heartbeater = None
docs: We lost our connection - stop our heartbeat.  This runs when the
          protocol wants a disconnection.
  
          This redundant output ensures that the heartbeater stops
          immediately after the connection is lost.  Twisted will call
          connectionLost after loseConnection, but between the two the
          heartbeat-writing callback may run, after the transport's been
          lost.  Relying on connectionLost to cancel our
          callback thus creates a race condition.