code: def close(self):
          
  
          try:
              self.conn
          except AttributeError:
              pass
          else:
              self.conn.send_bytes(dumps(('close', (), {}), 2))
              self.conn.close()
              del self.conn
docs: Shutdown server