Python源码示例:concurrent.futures.TimeoutError()

示例1
def _check_executor(self, dt):
        start = time()
        try:
            for future in as_completed(self._futures[:], 0):
                self._futures.remove(future)
                try:
                    result = future.result()
                except Exception:
                    traceback.print_exc()
                    # make an error tile?
                    continue
                if result is None:
                    continue
                callback, args = result
                callback(*args)

                # capped executor in time, in order to prevent too much
                # slowiness.
                # seems to works quite great with big zoom-in/out
                if time() - start > self.cap_time:
                    break
        except TimeoutError:
            pass 
示例2
def _run_query(self, query):
    query_job = self._client.query(query)
    num_retries = 0
    while True:
      try:
        iterator = query_job.result(timeout=300)
      except TimeoutError as e:
        logging.warning('Time out waiting for query: %s', query)
        if num_retries < bigquery_util.BQ_NUM_RETRIES:
          num_retries += 1
          time.sleep(90)
        else:
          raise e
      else:
        break
    result = []
    for i in iterator:
      result.append(str(i.values()[0]))
    return result 
示例3
def _copy_to_flatten_table(self, output_table_id, cp_query):
    job_config = bigquery.job.QueryJobConfig(destination=output_table_id)
    query_job = self._client.query(cp_query, job_config=job_config)
    num_retries = 0
    while True:
      try:
        _ = query_job.result(timeout=600)
      except TimeoutError as e:
        logging.warning('Time out waiting for query: %s', cp_query)
        if num_retries < bigquery_util.BQ_NUM_RETRIES:
          num_retries += 1
          time.sleep(90)
        else:
          logging.error('Copy to table query failed: %s', output_table_id)
          raise e
      else:
        break
    logging.info('Copy to table query was successful: %s', output_table_id) 
示例4
def start_suite(self, suite: TestSuite) -> None:
        """Form list of tests for the Robot Framework test suite that are included in the TestRail test run.

        If analysis depth of the run results is greater than zero, when first suite is launched
        a list of 'testrailid' tags of stable test cases is obtained.
        After that the list of tags is written to the class attribute and for subsequent suites the obtaining is not happening.

        If analysis depth of the run results is zero, when the first suite is launched
        a list of 'testrailid' tags of all test cases in the given status is obtained.
        After that the list of tags is written to the class attribute and for subsequent suites the obtaining is not happening.

        *Args:*\n
            _suite_ - Robot Framework test suite object.
        """
        tests = suite.tests
        suite.tests = None
        try:
            if self.results_depth > 0:
                suite.tests = [t for t in tests if (set(t.tags) & set(self.tr_stable_tags_list))]
            else:
                suite.tests = [t for t in tests if (set(t.tags) & set(self.tr_tags_list))]
        except (RequestException, TimeoutError) as error:
            self._log_to_parent_suite(suite, str(error)) 
示例5
def run(self):
        while not self.closed:
            try:
                segment, future = self.futures.get(block=True, timeout=0.5)
            except queue.Empty:
                continue

            # End of stream
            if future is None:
                break

            while not self.closed:
                try:
                    result = future.result(timeout=0.5)
                except futures.TimeoutError:
                    continue
                except futures.CancelledError:
                    break

                if result is not None:
                    self.write(segment, result)

                break

        self.close() 
示例6
def connect_and_auth(host, port, password, prot, loop, log, timeout=0.5):
    """Try to create a connection and authenticate to the
    target FS ESL.
    """
    msg = ("Failed to connect to server at '{}:{}'\n"
           "Please check that FreeSWITCH is running and "
           "accepting ESL connections.".format(host, port))
    try:
        await asyncio.wait_for(
            loop.create_connection(lambda: prot, host, port),
            timeout=timeout)
    except (
        ConnectionRefusedError, asyncio.TimeoutError, OSError,
        futures.TimeoutError,
    ) as err:
        raise ConnectionError(msg.format(host, port))

    # TODO: consider using the asyncio_timeout lib here
    try:
        await asyncio.wait_for(prot.authenticate(), timeout)
    except asyncio.TimeoutError:
        raise ConnectionRefusedError(msg.format(host, port)) 
示例7
def poll(self, events, timeout=None,
                   return_when=asyncio.FIRST_COMPLETED):
        """Poll for any of a set of event types to be received for this session.
        """
        awaitables = {}
        for name in events:
            awaitables[self.recv(name)] = name
        done, pending = await asyncio.wait(
            awaitables, timeout=timeout, return_when=return_when)

        if done:
            ev_dicts = []
            for fut in done:
                awaitables.pop(fut)
                ev_dicts.append(fut.result())
            return ev_dicts, awaitables.values()
        else:
            raise asyncio.TimeoutError(
                "None of {} was received in {} seconds"
                .format(events, timeout))

    # call control / 'mod_commands' methods
    # TODO: dynamically add @decorated functions to this class
    # and wrap them using functools.update_wrapper ...? 
示例8
def _receive_credential(self, result_type: CredentialType) -> Optional[str]:
        if self.cancelled:
            return None
        self.current_status = {
            "next_step": result_type.value,
        }
        if result_type == CredentialType.AUTHORIZATION:
            self.current_status["manual_auth_url"] = make_login_url(self.device_name)
        try:
            return self.queue.send_to_async(self.current_status,
                                            lambda: self._set_expecting(result_type))
        except futures.TimeoutError:
            self.cancel()
            return None
        except futures.CancelledError:
            return None 
示例9
def test_zero_timeout(self):
        future1 = self.executor.submit(time.sleep, 2)
        completed_futures = set()
        try:
            for future in futures.as_completed(
                    [CANCELLED_AND_NOTIFIED_FUTURE,
                     EXCEPTION_FUTURE,
                     SUCCESSFUL_FUTURE,
                     future1],
                    timeout=0):
                completed_futures.add(future)
        except futures.TimeoutError:
            pass

        self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE,
                              EXCEPTION_FUTURE,
                              SUCCESSFUL_FUTURE]),
                         completed_futures) 
示例10
def run(self):
        self.brain.connect()
        self.rtm_connect()
        if not self.client.server.connected:
            raise RuntimeError(
                'Can not connect to slack client. Check your settings.'
            )

        while True:
            events = self.read_message()
            if events:
                messages = self.extract_messages(events)
                if messages:
                    with ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
                        try:
                            executor.map(self.handle_message, messages)
                        except TimeoutError:
                            self.logger.error(traceback.format_exc())
            else:
                time.sleep(0.3) 
示例11
def test_zero_timeout(self):
        future1 = self.executor.submit(time.sleep, 2)
        completed_futures = set()
        try:
            for future in futures.as_completed(
                    [CANCELLED_AND_NOTIFIED_FUTURE,
                     EXCEPTION_FUTURE,
                     SUCCESSFUL_FUTURE,
                     future1],
                    timeout=0):
                completed_futures.add(future)
        except futures.TimeoutError:
            pass

        self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE,
                              EXCEPTION_FUTURE,
                              SUCCESSFUL_FUTURE]),
                         completed_futures) 
示例12
def _check_executor(self, dt):
        start = time()
        try:
            for future in as_completed(self._futures[:], 0):
                self._futures.remove(future)
                try:
                    result = future.result()
                except Exception:
                    traceback.print_exc()
                    # make an error tile?
                    continue
                if result is None:
                    continue
                callback, args = result
                callback(*args)

                # capped executor in time, in order to prevent too much
                # slowiness.
                # seems to works quite great with big zoom-in/out
                if time() - start > self.cap_time:
                    break
        except TimeoutError:
            pass 
示例13
def queue_message(self, channel_id:str, msg):
		embed = '0'
		if type(msg) == discord.Embed:
			embed = '1'
			msg = jsonpickle.encode(msg)
		else:
			msg = str(msg)
		message_id = random.randint(0, 1000000)
		payload = {'key': 'verysecretkey', 'id': message_id, 'channel_id': channel_id, 'message': msg, 'embed': embed}
		try:
			with aiohttp.Timeout(15):
				async with self.session.post('http://ip:port/queue', data=payload) as r:
					return True
		except (asyncio.TimeoutError, aiohttp.errors.ClientConnectionError, aiohttp.errors.ClientError):
			await asyncio.sleep(5)
			return
		except Exception as e:
			print('queue error: '+str(e)) 
示例14
def run_process(self, code, response=False):
		try:
			loop = self.bot.loop
			exit_future = asyncio.Future(loop=loop)
			create = loop.subprocess_exec(lambda: DataProtocol(exit_future),
																		*code, stdin=None, stderr=None)
			transport, protocol = await asyncio.wait_for(create, timeout=30)
			await exit_future
			if response:
				data = bytes(protocol.output)
				return data.decode('ascii').rstrip()
			return True
		except asyncio.TimeoutError:
			return False
		except Exception as e:
			print(e)
		finally:
			transport.close() 
示例15
def test_zero_timeout(self):
        future1 = self.executor.submit(time.sleep, 2)
        completed_futures = set()
        try:
            for future in futures.as_completed(
                    [CANCELLED_AND_NOTIFIED_FUTURE,
                     EXCEPTION_FUTURE,
                     SUCCESSFUL_FUTURE,
                     future1],
                    timeout=0):
                completed_futures.add(future)
        except futures.TimeoutError:
            pass

        self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE,
                              EXCEPTION_FUTURE,
                              SUCCESSFUL_FUTURE]),
                         completed_futures) 
示例16
def test_events_wrong_source(self):
        objects = self.srv.get_objects_node()
        o = objects.add_object(3, 'MyObject')
        evgen = self.srv.get_event_generator(source=o)

        myhandler = MySubHandler()
        sub = self.opc.create_subscription(100, myhandler)
        handle = sub.subscribe_events()

        tid = datetime.utcnow()
        msg = b"this is my msg "
        evgen.trigger(tid, msg)

        with self.assertRaises(TimeoutError):  # we should not receive event
            ev = myhandler.future.result(2)

        # time.sleep(0.1)
        sub.unsubscribe(handle)
        sub.delete() 
示例17
def test_wait(self):

        mutable = []

        @threads(N)
        def side_effects():
            mutable.append(True)

        result = side_effects()
        result._wait()
        assert mutable[0]

        @threads(N, timeout=0.1)
        def side_effects_timeout():
            time.sleep(1) 

        result = side_effects_timeout()
        with self.assertRaises(TimeoutError):
            result._wait() 
示例18
def submit(self, label, command, opts):
        """Submit a bgutil command to run it asynchronously."""
        task = BgUtilTask(label, datetime.now())
        self.tasks.append(task)

        def _done_callback(f):
            try:
                result = f.result()
                task.completed(result)
            except futures.CancelledError as e:
                task.cancelled(e)
            except futures.TimeoutError as e:
                task.timed_out(e)
            except Exception as e:
                task.failed(e)

        future = self._executor.submit(
            self._wrap_command, task, context.accessor, command, opts
        )
        task.submitted()
        future.add_done_callback(_done_callback) 
示例19
def test_id_getter_setter(self):
        """Future.get_id/get_id works in isolation as expected."""

        f = Future(solver=None, id_=None)

        # f.id should be None
        self.assertIsNone(f.id)
        with self.assertRaises(TimeoutError):
            f.wait_id(timeout=1)

        # set it
        submission_id = 'test-id'
        f.id = submission_id

        # validate it's available
        self.assertEqual(f.wait_id(), submission_id)
        self.assertEqual(f.wait_id(timeout=1), submission_id)
        self.assertEqual(f.id, submission_id) 
示例20
def wait_id(self, timeout=None):
        """Blocking id getter.

        Return the submitted problem ID, but unlike :meth:`.id`, block until the
        ID becomes known, or until `timeout` expires.

        Args:
            timeout (float, default=None):
                Timeout in seconds. By default, wait indefinitely for problem
                id to become known/available.

        Returns:
            str:
                Problem ID, as returned by SAPI.

        Raises:
            :exc:`concurrent.futures.TimeoutError`:
                When `timeout` exceeded, and problem id not ready.

        """
        if not self._id_ready_event.wait(timeout=timeout):
            raise TimeoutError("problem id not available yet")

        return self._id 
示例21
def table_empty(project_id, dataset_id, table_id):
  client = bigquery.Client(project=project_id)
  num_rows = 'num_rows'
  query = 'SELECT count(0) AS {COL_NAME} FROM {DATASET_ID}.{TABLE_ID}'.format(
      COL_NAME=num_rows, DATASET_ID=dataset_id, TABLE_ID=table_id)
  query_job = client.query(query)
  num_retries = 0
  while True:
    try:
      results = query_job.result(timeout=300)
    except TimeoutError as e:
      logging.warning('Time out waiting for query: %s', query)
      if num_retries < BQ_NUM_RETRIES:
        num_retries += 1
        time.sleep(90)
      else:
        raise e
    else:
      if results.total_rows == 1:
        break
      else:
        logging.error('Query did not returned expected # of rows: %s', query)
        if num_retries < BQ_NUM_RETRIES:
          num_retries += 1
          time.sleep(90)
        else:
          raise ValueError('Expected 1 row in query result, got {}'.format(
              results.total_rows))

  row = list(results)[0]
  col_names = row.keys()
  if set(col_names) != {num_rows}:
    logging.error('Query `%s` did not return expected `%s` column.',
                  query, num_rows)
    raise ValueError(
        'Expected `{COL_NAME}` column is missing in the query result.'.format(
            COL_NAME=num_rows))
  return row.get(num_rows) == 0 
示例22
def get_flatten_table_schema(self, schema_file_path):
    # type: (str) -> bool
    """Write the flatten table's schema to the given json file.

    This method basically performs the following tasks:
      * Extract variant table schema using BigQuery API.
      * Copy all columns without any change except `call` column:
        * Modify mode from REPEATED TO NULLABLE
        * Duplicate call.sample_id column as sample_id column (for partitioning)

    Args:
      schema_file_path: The json schema will be written to this file.

    Returns;
      A bool value indicating if the schema was successfully extracted.
    """
    full_table_id = '{}.{}.{}'.format(
        self._project_id, self._dataset_id, self._schema_table_id)
    try:
      variant_table = self._client.get_table(full_table_id)
    except TimeoutError as e:
      logging.error('Failed to get table using its id: "%s"', full_table_id)
      raise e
    variant_schema = variant_table.schema
    sample_schema = self._convert_variant_schema_to_sample_schema(
        variant_schema)
    with open(schema_file_path, 'w') as outfile:
      json.dump(sample_schema, outfile, sort_keys=True, indent=2)
    logging.info('Successfully extracted the schema of flatten table.')
    return True 
示例23
def run_assertion(self):
    query_job = self._client.query(self._query)
    num_retries = 0
    while True:
      try:
        results = query_job.result(timeout=300)
      except TimeoutError as e:
        print 'WARNING: Time out waiting for query: {}'.format(self._query)
        if num_retries < _NUM_QUERY_RETIRES:
          num_retries += 1
          time.sleep(90)
        else:
          raise e
      else:
        if results.total_rows == 1:
          break
        else:
          print 'ERROR: Query `{}` did not return expected num rows: {}'.format(
              self._query, results.total_rows)
          if num_retries < _NUM_QUERY_RETIRES:
            num_retries += 1
            time.sleep(90)
          else:
            raise run_tests_common.TestCaseFailure(
                'Expected 1 row query results instead got {} in test {}'.format(
                    results.total_rows, self._test_name))

    row = list(results)[0]
    col_names = row.keys()
    if set(self._expected_result.keys()) != set(col_names):
      raise run_tests_common.TestCaseFailure(
          'Expected {} columns in the query result, got {} in test {}'.format(
              self._expected_result.keys(), col_names, self._test_name))
    for key in self._expected_result.keys():
      if self._expected_result.get(key) != row.get(key):
        raise run_tests_common.TestCaseFailure(
            'Column {} mismatch: expected {}, got {} in test {}'.format(
                key, self._expected_result[key], row.get(key), self._test_name)) 
示例24
def wait(self, _timeout=None):
        if self._awaited:
            try:
                self._future.result(timeout=_timeout)
            except FutureTimeoutError:
                self.set_timedout()
            except FutureCancelledError:
                self.cancel()
        return self 
示例25
def stop_video_streaming(self):
        """
        Stops the live video stream from the drone front camera

        :rtype: ReturnTuple
        """
        if self._pdraw is None:
            msg = "Cannot start streaming while the drone is not connected"
            self.logger.error(msg)
            return makeReturnTuple(ErrorCodeDrone.ERROR_BAD_STATE, msg)

        if self._pdraw.is_legacy():
            f = self._thread_loop.run_async(
                self._disable_legacy_video_streaming_impl)
            try:
                if not f.result_or_cancel(timeout=5):
                    msg = "Unable to disable legacy video streaming"
                    self.logger.error(msg)
                    return makeReturnTuple(ErrorCodeDrone.ERROR_BAD_STATE, msg)
            except FutureTimeoutError:
                msg = "Unable to disable legacy video streaming (timeout)"
                self.logger.error(msg)
                return makeReturnTuple(ErrorCodeDrone.ERROR_BAD_STATE, msg)

        try:
            if not self._pdraw.pause().result_or_cancel(timeout=5):
                msg = "Failed to pause video stream"
                self.logger.error(msg)
                return makeReturnTuple(ErrorCodeDrone.ERROR_BAD_STATE, msg)
            if not self._pdraw.close().result_or_cancel(timeout=5):
                msg = "Failed to close video stream"
                self.logger.error(msg)
                return makeReturnTuple(ErrorCodeDrone.ERROR_BAD_STATE, msg)
        except FutureTimeoutError:
            msg = "Failed to stop video stream (timeout)"
            self.logger.error(msg)
            return makeReturnTuple(ErrorCodeDrone.ERROR_BAD_STATE, msg)

        return makeReturnTuple(self.error_code_drones.OK, "Video stream paused") 
示例26
def __check_connection(self):
        try:
            node = self.client.get_root_node()
            node.get_children()
            if not self.__server_conf.get("disableSubscriptions", False) and (not self.__connected or not self.subscribed):
                self.__sub = self.client.create_subscription(self.__server_conf.get("subCheckPeriodInMillis", 500), self.__sub_handler)
            self.__connected = True
        except ConnectionRefusedError:
            self.__connected = False
            self._subscribed = {}
            self.__available_object_resources = {}
            self.__sub = None
        except OSError:
            self.__connected = False
            self._subscribed = {}
            self.__available_object_resources = {}
            self.__sub = None
        except FuturesTimeoutError:
            self.__connected = False
            self._subscribed = {}
            self.__available_object_resources = {}
            self.__sub = None
        except AttributeError:
            self.__connected = False
            self._subscribed = {}
            self.__available_object_resources = {}
            self.__sub = None
        except Exception as e:
            self.__connected = False
            self._subscribed = {}
            self.__available_object_resources = {}
            self.__sub = None
            log.exception(e) 
示例27
def scan_nodes_from_config(self):
        try:
            if self.__interest_nodes:
                for device_object in self.__interest_nodes:
                    for current_device in device_object:
                        try:
                            device_configuration = device_object[current_device]
                            devices_info_array = self.__search_general_info(device_configuration)
                            for device_info in devices_info_array:
                                if device_info is not None and device_info.get("deviceNode") is not None:
                                    self.__search_nodes_and_subscribe(device_info)
                                    self.__save_methods(device_info)
                                    self.__search_attribute_update_variables(device_info)
                                else:
                                    log.error("Device node is None, please check your configuration.")
                                    log.debug("Current device node is: %s", str(device_configuration.get("deviceNodePattern")))
                                    break
                        except BrokenPipeError:
                            log.debug("Broken Pipe. Connection lost.")
                        except OSError:
                            log.debug("Stop on scanning.")
                        except FuturesTimeoutError:
                            self.__check_connection()
                        except Exception as e:
                            log.exception(e)
                log.debug(self.__interest_nodes)
        except Exception as e:
            log.exception(e) 
示例28
def await_in_order(awaitables, loop, timeout=None):
    awaitables = map(partial(asyncio.ensure_future, loop=loop), awaitables)
    for awaitable in awaitables:
        try:
            res = await asyncio.wait_for(awaitable, timeout=timeout, loop=loop)
        except (asyncio.CancelledError, asyncio.TimeoutError) as err:
            for awaitable in awaitables:
                awaitable.cancel()
            raise

    return res 
示例29
def uuid(self):
        try:
            return self.events['Job-UUID']
        except KeyError:
            try:
                return self.fut.result()['Job-UUID']
            except futures.TimeoutError:
                self.log.warn(
                    "Response timeout for job {}"
                    .format(self.sess_uuid)
                ) 
示例30
def get(self, timeout=None):
        '''Get the result for this job waiting up to `timeout` seconds.
        Raises `TimeoutError` on if job does complete within alotted time.
        '''
        ready = self._sig.wait(timeout)
        if ready:
            return self._result
        elif timeout:
            raise TimeoutError("Job not complete after '{}' seconds"
                               .format(timeout))