class_docstr: Class that handles the requests arriving to the head and the results extracted from the requests future.
  
  :param metrics_registry: optional metrics registry for prometheus. Used if we need to expose metrics from the executor or from the data request handler
  :param runtime_name: optional runtime_name that will be registered during monitoring
docstr: Cancel endpoint_discovery_from_worker task if exists and is not completed. Cancellation is required if the Flow is being terminated before the
  task is successful or hasn't reached the max timeout.
docstr_tok: ["Cancel","endpoint_discovery_from_worker","task","if","exists","and","is","not","completed",".","Cancellation","is","required","if","the","Flow","is","being","terminated","before","the","task","is","successful","or","has","n't","reached","the","max","timeout","."]
code: def cancel_endpoint_discovery_from_workers_task(self):
      """Cancel endpoint_discovery_from_worker task if exists and is not completed. Cancellation is required if the Flow is being terminated before the
      task is successful or hasn't reached the max timeout.
      """
      if self.endpoints_discovery_task:
          try:
              if not self.endpoints_discovery_task.done():
                  self.logger.debug(
                      f"Cancelling endpoint discovery task."
                  )
                  self.endpoints_discovery_stop_event.set()  # this event is useless if simply cancel
                  self.endpoints_discovery_task.cancel()
          except Exception as ex:
              self.logger.debug(
                  f"exception during endpoint discovery task cancellation: {ex}"
              )
              pass
  
imports: import argparse
  import asyncio
  import json
  import os
  from collections import defaultdict
  from typing import TYPE_CHECKING, AsyncIterator, Dict, List, Optional, Tuple, Any
  import grpc
  from jina.enums import PollingType
  from jina.constants import __default_endpoint__
  from jina.excepts import InternalNetworkError
  from jina.helper import get_full_version
  from jina.proto import jina_pb2
  from jina.serve.networking import GrpcConnectionPool
  from jina.serve.runtimes.monitoring import MonitoringRequestMixin
  from jina.serve.runtimes.worker.request_handling import WorkerRequestHandler
  from jina.types.request.data import DataRequest, Response
  from jina._docarray import docarray_v2
label_desc: Use image node_id 5 for calling the HeaderRequestHandler obj's underlying member method code with example usage: obj.cancel_endpoint_discovery_from_workers_task() without return types