How to use the futures.as_completed function in futures

To help you get started, we’ve selected a few futures examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Juniper / juniper-newrelic-plugin / src / jnpr_nr_plugin / device / device_mgr.py View on Github external
def find_all_devices(self, device_cfg):
        devices_mp = dict()
        discovery_tp_size = self.config.get('discovery_tp_size', 5)
        devices = utils.get_device_list(device_cfg)
        with futures.ThreadPoolExecutor(discovery_tp_size) as tp_executor:
            results = {
                tp_executor.submit(
                    self.find_device,
                    device): device for device in devices}
            devices = [fut.result() for fut in futures.as_completed(results)]
            for device in devices:
                if device is not None and device.get(
                        'ip_address') not in devices_mp:
                    devices_mp[device.get('ip_address')] = device
        LOGGER.info(
            'get_all_devices, device_count [%d]', len(
                devices_mp.values()))
        self.active_devices = devices_mp.values()
        return self.active_devices
github Juniper / juniper-newrelic-plugin / src / jnpr_nr_plugin / main.py View on Github external
def process(self):
        LOGGER.warn('process, start ')
        start_time = time.time()
        with futures.ThreadPoolExecutor(len(self.collectors)) as tp_executor:
            results = {
                tp_executor.submit(
                    collector.collect): collector for collector in self.collectors}
            futures.as_completed(results)
        duration = time.time() - start_time
        self.next_wake_interval = self._wake_interval - duration
        if self.next_wake_interval < 1:
            LOGGER.warn('process, poll interval took greater than %is',
                        duration)
            self.next_wake_interval = int(self._wake_interval)
        LOGGER.warn('process, end in %.2fs, next poll will begin at %is from now',
                    duration, self.next_wake_interval)