def run(self, grid_point, *args): # Create all threads threads = set() livethreads = set() blockedthreads = set() for block_point in np.ndindex(*self._block_dim): def target(): self._f(*args) t = BlockThread(target, self, grid_point, block_point) t.start() threads.add(t) livethreads.add(t) # Potential optimisations: # 1. Continue the while loop immediately after finding a blocked thread # 2. Don't poll already-blocked threads while livethreads: for t in livethreads: if t.syncthreads_blocked: blockedthreads.add(t) elif t.exception: reraise(*(t.exception)) if livethreads == blockedthreads: for t in blockedthreads: t.syncthreads_blocked = False t.syncthreads_event.set() blockedthreads = set() livethreads = set([ t for t in livethreads if t.is_alive() ]) # Final check for exceptions in case any were set prior to thread # finishing, before we could check it for t in threads: if t.exception: reraise(*(t.exception))
def new_error_context(fmt_, *args, **kwargs): """ A contextmanager that prepend contextual information to any exception raised within. If the exception type is not an instance of NumbaError, it will be wrapped into a InternalError. The exception class can be changed by providing a "errcls_" keyword argument with the exception constructor. The first argument is a message that describes the context. It can be a format string. If there are additional arguments, it will be used as ``fmt_.format(*args, **kwargs)`` to produce the final message string. """ errcls = kwargs.pop('errcls_', InternalError) loc = kwargs.get('loc', None) if loc is not None and not loc.filename.startswith(_numba_path): loc_info.update(kwargs) try: yield except NumbaError as e: e.add_context(_format_msg(fmt_, args, kwargs)) raise except Exception as e: newerr = errcls(e).add_context(_format_msg(fmt_, args, kwargs)) six.reraise(type(newerr), newerr, sys.exc_info()[2])
def new_error_context(fmt_, *args, **kwargs): """ A contextmanager that prepend contextual information to any exception raised within. If the exception type is not an instance of NumbaError, it will be wrapped into a InternalError. The exception class can be changed by providing a "errcls_" keyword argument with the exception constructor. The first argument is a message that describes the context. It can be a format string. If there are additional arguments, it will be used as ``fmt_.format(*args, **kwargs)`` to produce the final message string. """ errcls = kwargs.pop('errcls_', InternalError) loc = kwargs.get('loc', None) if loc is not None and not loc.filename.startswith(_numba_path): loc_info.update(kwargs) try: yield except NumbaError as e: e.add_context(_format_msg(fmt_, args, kwargs)) raise except Exception as e: newerr = errcls(e).add_context(_format_msg(fmt_, args, kwargs)) from numba import config tb = sys.exc_info()[2] if config.FULL_TRACEBACKS else None six.reraise(type(newerr), newerr, tb)
def run(self, grid_point, *args): # Create all threads threads = set() livethreads = set() blockedthreads = set() for block_point in np.ndindex(*self._block_dim): def target(): self._f(*args) t = BlockThread(target, self, grid_point, block_point) t.start() threads.add(t) livethreads.add(t) # Potential optimisations: # 1. Continue the while loop immediately after finding a blocked thread # 2. Don't poll already-blocked threads while livethreads: for t in livethreads: if t.syncthreads_blocked: blockedthreads.add(t) elif t.exception: reraise(*(t.exception)) if livethreads == blockedthreads: for t in blockedthreads: t.syncthreads_blocked = False t.syncthreads_event.set() blockedthreads = set() livethreads = set([t for t in livethreads if t.is_alive()]) # Final check for exceptions in case any were set prior to thread # finishing, before we could check it for t in threads: if t.exception: reraise(*(t.exception))
def error_rewrite(e, issue_type): """ Rewrite and raise Exception `e` with help supplied based on the specified issue_type. """ if config.SHOW_HELP: help_msg = errors.error_extras[issue_type] e.patch_message(''.join(e.args) + help_msg) if config.FULL_TRACEBACKS: raise e else: reraise(type(e), e, None)
def new_error_context(fmt_, *args, **kwargs): """ A contextmanager that prepend contextual information to any exception raised within. If the exception type is not an instance of NumbaError, it will be wrapped into a InternalError. The exception class can be changed by providing a "errcls_" keyword argument with the exception constructor. The first argument is a message that describes the context. It can be a format string. If there are additional arguments, it will be used as ``fmt_.format(*args, **kwargs)`` to produce the final message string. """ errcls = kwargs.pop('errcls_', InternalError) try: yield except NumbaError as e: e.add_context(_format_msg(fmt_, args, kwargs)) raise except Exception as e: newerr = errcls(e).add_context(_format_msg(fmt_, args, kwargs)) six.reraise(type(newerr), newerr, sys.exc_info()[2])
def _compile_for_args(self, *args, **kws): """ For internal use. Compile a specialized version of the function for the given *args* and *kws*, and return the resulting callable. """ assert not kws argtypes = [] for a in args: if isinstance(a, OmittedArg): argtypes.append(types.Omitted(a.value)) else: argtypes.append(self.typeof_pyval(a)) try: return self.compile(tuple(argtypes)) except errors.TypingError as e: # Intercept typing error that may be due to an argument # that failed inferencing as a Numba type failed_args = [] for i, arg in enumerate(args): val = arg.value if isinstance(arg, OmittedArg) else arg try: tp = typeof(val, Purpose.argument) except ValueError as typeof_exc: failed_args.append((i, str(typeof_exc))) else: if tp is None: failed_args.append( (i, "cannot determine Numba type of value %r" % (val,))) if failed_args: # Patch error message to ease debugging msg = str(e).rstrip() + ( "\n\nThis error may have been caused by the following argument(s):\n%s\n" % "\n".join("- argument %d: %s" % (i, err) for i, err in failed_args)) e.patch_message(msg) # add in help info if config.SHOW_HELP: help_msg = errors.error_extras['typing'] e.patch_message(''.join(e.args) + help_msg) # raise if config.FULL_TRACEBACKS: raise e else: reraise(type(e), e, None) except errors.UnsupportedError as e: # Something unsupported is present in the user code, add help info if config.SHOW_HELP: help_msg = errors.error_extras['unsupported_error'] e.patch_message(''.join(e.args) + help_msg) if config.FULL_TRACEBACKS: raise e else: reraise(type(e), e, None) except Exception as e: if config.SHOW_HELP: if hasattr(e, 'patch_message'): help_msg = errors.error_extras['reportable'] e.patch_message(''.join(e.args) + help_msg) # ignore the FULL_TRACEBACKS config, this needs reporting! raise e
def _compile_for_args(self, *args, **kws): """ For internal use. Compile a specialized version of the function for the given *args* and *kws*, and return the resulting callable. """ assert not kws argtypes = [] for a in args: if isinstance(a, OmittedArg): argtypes.append(types.Omitted(a.value)) else: argtypes.append(self.typeof_pyval(a)) try: return self.compile(tuple(argtypes)) except errors.TypingError as e: # Intercept typing error that may be due to an argument # that failed inferencing as a Numba type failed_args = [] for i, arg in enumerate(args): val = arg.value if isinstance(arg, OmittedArg) else arg try: tp = typeof(val, Purpose.argument) except ValueError as typeof_exc: failed_args.append((i, str(typeof_exc))) else: if tp is None: failed_args.append( (i, "cannot determine Numba type of value %r" % (val, ))) if failed_args: # Patch error message to ease debugging msg = str(e).rstrip() + ( "\n\nThis error may have been caused by the following argument(s):\n%s\n" % "\n".join("- argument %d: %s" % (i, err) for i, err in failed_args)) e.patch_message(msg) # add in help info if config.SHOW_HELP: help_msg = errors.error_extras['typing'] e.patch_message(''.join(e.args) + help_msg) # raise if config.FULL_TRACEBACKS: raise e else: reraise(type(e), e, None) except errors.UnsupportedError as e: # Something unsupported is present in the user code, add help info if config.SHOW_HELP: help_msg = errors.error_extras['unsupported_error'] e.patch_message(''.join(e.args) + help_msg) if config.FULL_TRACEBACKS: raise e else: reraise(type(e), e, None) except Exception as e: if config.SHOW_HELP: if hasattr(e, 'patch_message'): help_msg = errors.error_extras['reportable'] e.patch_message(''.join(e.args) + help_msg) # ignore the FULL_TRACEBACKS config, this needs reporting! raise e