code: def register(listener):
      
      if not isinstance(listener, _EventListener):
          raise TypeError("Listeners for %s must be either a "
                          "CommandListener, ServerHeartbeatListener, "
                          "ServerListener, or TopologyListener." % (listener,))
      if isinstance(listener, CommandListener):
          _LISTENERS.command_listeners.append(listener)
      if isinstance(listener, ServerHeartbeatListener):
          _LISTENERS.server_heartbeat_listeners.append(listener)
      if isinstance(listener, ServerListener):
          _LISTENERS.server_listeners.append(listener)
      if isinstance(listener, TopologyListener):
          _LISTENERS.topology_listeners.append(listener)
docs: Register a global event listener.
  
      :Parameters:
        - `listener`: A subclasses of :class:`CommandListener`,
          :class:`ServerHeartbeatListener`, :class:`ServerListener`, or
          :class:`TopologyListener`.