(self)
Run queries in multiple threads and wait for completion.
Run queries in multiple threads and wait for completion.
Run queries in multiple threads and wait for completion .
def collect_metrics_async(self):
        # type: () -> None
        """Run queries in multiple threads and wait for completion."""
        tasks = []
        try:
            for query_specs in self.make_query_specs():
                tasks.append(self.thread_pool.submit(self.query_metrics_wrapper, query_specs))
        except Exception as e:
            self.log.warning("Unable to schedule all metric collection tasks: %s", e)
        finally:
            self.log.debug("Queued all %d tasks, waiting for completion.", len(tasks))
            for future in as_completed(tasks):
                future_exc = future.exception()
                if isinstance(future_exc, vmodl.fault.InvalidArgument):
                    # The query was invalid or the resource does not have values for this metric.
                    continue
                elif future_exc is not None:
                    self.log.warning("A metric collection API call failed with the following error: %s", future_exc)
                    continue

                results = future.result()
                if not results:
                    self.log.debug("A metric collection API call did not return data.")
                    continue

                try:
                    # Callback is called in the main thread
                    self.submit_metrics_callback(results)
                except Exception as e:
                    self.log.exception(
                        "Exception '%s' raised during the submit_metrics_callback. "
                        "Ignoring the error and continuing execution.",
                        e,
                    )
def collect_metrics_async ( self ) : # type: () -> None tasks = [ ] try : for query_specs in self . make_query_specs ( ) : tasks . append ( self . thread_pool . submit ( self . query_metrics_wrapper , query_specs ) ) except Exception as e : self . log . warning ( "Unable to schedule all metric collection tasks: %s" , e ) finally : self . log . debug ( "Queued all %d tasks, waiting for completion." , len ( tasks ) ) for future in as_completed ( tasks ) : future_exc = future . exception ( ) if isinstance ( future_exc , vmodl . fault . InvalidArgument ) : # The query was invalid or the resource does not have values for this metric. continue elif future_exc is not None : self . log . warning ( "A metric collection API call failed with the following error: %s" , future_exc ) continue results = future . result ( ) if not results : self . log . debug ( "A metric collection API call did not return data." ) continue try : # Callback is called in the main thread self . submit_metrics_callback ( results ) except Exception as e : self . log . exception ( "Exception '%s' raised during the submit_metrics_callback. " "Ignoring the error and continuing execution." , e , )