How to use the future.utils.raise_with_traceback function in future

To help you get started, we’ve selected a few future 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 pyglet / pyglet / tests / extlibs / future / py2_3 / future / backports / urllib / request.py View on Github external
self.type = urltype
        name = name.replace('-', '_')
        if not hasattr(self, name):
            if proxy:
                return self.open_unknown_proxy(proxy, fullurl, data)
            else:
                return self.open_unknown(fullurl, data)
        try:
            if data is None:
                return getattr(self, name)(url)
            else:
                return getattr(self, name)(url, data)
        except HTTPError:
            raise
        except socket.error as msg:
            raise_with_traceback(IOError('socket error', msg))
github airbnb / omniduct / omniduct / utils / decorators.py View on Github external
failed function call once more.
    """
    if not self._Duct__connected:
        self.connect()

    try:
        return f(self, *args, **kwargs)
    except Exception as e:
        # Check to see if it is possible that we failed due to connection issues.
        # If so, try again once more. If we fail again, raise.
        # TODO: Explore adding a DuctConnectionError class and filter this
        # handling to errors of that class.
        if not self.is_connected():
            self.connect()
            return f(self, *args, **kwargs)
        raise_with_traceback(e)
github criteo / biggraphite / biggraphite / drivers / cassandra.py View on Github external
start_key, end_key, shard, nshards, callback_on_progress
            )
        except Exception as e:
            first_exception = e
            log.exception("Failed to clean directories.")

        try:
            self._clean_expired_metrics(
                max_age, start_key, end_key, shard, nshards, callback_on_progress
            )
        except Exception as e:
            first_exception = e
            log.exception("Failed to clean metrics.")

        if first_exception is not None:
            raise_with_traceback(first_exception)
github dagster-io / dagster / python_modules / dagster / dagster / check / __init__.py View on Github external
def str_param(obj, param_name):
    if not _is_str(obj):
        raise_with_traceback(_param_type_mismatch_exception(obj, str, param_name))
    return obj
github googleapis / gax-python / google / gax / api_callable.py View on Github external
def inner(*args, **kwargs):
        """Wraps specified exceptions"""
        try:
            return a_func(*args, **kwargs)
        # pylint: disable=catching-non-exception
        except tuple(to_catch) as exception:
            utils.raise_with_traceback(
                gax.errors.create_error('RPC failed', cause=exception))
github PythonCharmers / python-future / src / future / backports / urllib / request.py View on Github external
for attr in attrs:
                attr, value = splitvalue(attr)
                if attr.lower() == 'type' and \
                   value in ('a', 'A', 'i', 'I', 'd', 'D'):
                    type = value.upper()
            (fp, retrlen) = self.ftpcache[key].retrfile(file, type)
            mtype = mimetypes.guess_type("ftp:" + url)[0]
            headers = ""
            if mtype:
                headers += "Content-Type: %s\n" % mtype
            if retrlen is not None and retrlen >= 0:
                headers += "Content-Length: %d\n" % retrlen
            headers = email.message_from_string(headers)
            return addinfourl(fp, headers, "ftp:" + url)
        except ftperrors() as exp:
            raise_with_traceback(URLError('ftp error %r' % exp))
github apache / beam / sdks / python / apache_beam / utils / retry.py View on Github external
while True:
        try:
          return fun(*args, **kwargs)
        except Exception as exn:  # pylint: disable=broad-except
          if not retry_filter(exn):
            raise
          # Get the traceback object for the current exception. The
          # sys.exc_info() function returns a tuple with three elements:
          # exception type, exception value, and exception traceback.
          exn_traceback = sys.exc_info()[2]
          try:
            try:
              sleep_interval = next(retry_intervals)
            except StopIteration:
              # Re-raise the original exception since we finished the retries.
              raise_with_traceback(exn, exn_traceback)

            logger(
                'Retry with exponential backoff: waiting for %s seconds before '
                'retrying %s because we caught exception: %s '
                'Traceback for above exception (most recent call last):\n%s',
                sleep_interval,
                getattr(fun, '__name__', str(fun)),
                ''.join(traceback.format_exception_only(exn.__class__, exn)),
                ''.join(traceback.format_tb(exn_traceback)))
            clock.sleep(sleep_interval)
          finally:
            # Traceback objects in locals can cause reference cycles that will
            # prevent garbage collection. Clear it now since we do not need
            # it anymore.
            exn_traceback = None
github douglas / toxiproxy-python / toxiproxy / api.py View on Github external
def validate_response(response):
    """
    Handle the received response to make sure that we
    will only process valid requests.
    """

    content = response.content

    if response.status_code == 409:
        raise_with_traceback(ProxyExists(content))
    elif response.status_code == 404:
        raise_with_traceback(NotFound(content))
    elif response.status_code == 400:
        raise_with_traceback(InvalidToxic(content))

    return response
github frictionlessdata / tableschema-py / jsontableschema / types.py View on Github external
longitude = json_value[0]
                    latitude = json_value[1]

                try:
                    geopoints = [decimal.Decimal(longitude),
                                 decimal.Decimal(latitude)]
                    self._check_latitude_longtiude_range(geopoints)
                    return geopoints
                except decimal.DecimalException as e:
                    raise_with_traceback(exceptions.InvalidGeoPointType(e))
            else:
                raise exceptions.InvalidGeoPointType(
                    '{0}: point is not of length 2'.format(value)
                )
        except (TypeError, ValueError) as e:
            raise_with_traceback(exceptions.InvalidGeoPointType(e))
github dagster-io / dagster / python_modules / dagster / dagster / check / __init__.py View on Github external
def opt_numeric_param(obj, param_name):
    if obj is not None and not isinstance(obj, (int, float)):
        raise_with_traceback(_param_type_mismatch_exception(obj, (int, float), param_name))
    return obj