Exemplo n.º 1
0
 def unwrap_value(self):
     if self.deleted:
         raise ExaquteException("Using deleted object")
     if not self.keep and self not in _temp_objects:
         raise ExaquteException(
             f"Using temporary object after submit point, object created at:\n{self.traceback}",
         )
     return _obj_to_value(self.value)
Exemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     self.processes = 1
     if "processes" in kwargs:
         self.processes = kwargs["processes"]
     else:
         raise ExaquteException("Number of processes not specified")
     if "runner" not in kwargs:
         raise ExaquteException("Runner must be specified")
     for k, v in kwargs.items():
         if k not in ("processes", "runner", "flags"):
             if not k.endswith("_layout"):
                 raise ExaquteException("Argument '{}' is not valid".format(k))
Exemplo n.º 3
0
def _init():
    global _exaqute_inited
    global _temp_objects
    if _exaqute_inited:
        raise ExaquteException("Init called twice")
    _exaqute_inited = True
    _temp_objects = set()
Exemplo n.º 4
0
 def wrapped_task(*args, **kwargs):
     _check_init()
     if _is_nested():
         return f(*args, **kwargs)
     if "returns" in kwargs:
         returns = kwargs.pop("returns")
     else:
         returns = self.returns
     if "keep" in kwargs:
         keep = kwargs.pop("keep")
     else:
         keep = self.keep
     new_args = [_obj_to_value(obj) for obj in args]
     for k, v in kwargs.items():
         kwargs[k] = _obj_to_value(v)
     result = f(*new_args, **kwargs)
     if returns != 1:
         if not hasattr(result, "__len__") or len(result) != returns:
             raise ExaquteException(
                 "Invalid number of results returned (expected {})".format(
                     returns
                 )
             )
         return [ValueWrapper(r, keep) for r in result]
     else:
         return ValueWrapper(result, keep)
Exemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     self.args = args
     self.returns = 1
     self.priority = False
     self.keep = False
     if "returns" in kwargs:
         self.returns = kwargs.pop("returns")
     if "priority" in kwargs:
         self.priority = kwargs.pop("priority")
     if "keep" in kwargs:
         self.keep = kwargs.pop("keep")
     for k, v in kwargs.items():
         if v not in (
                 IN,
                 INOUT,
                 FILE_IN,
                 FILE_OUT,
                 FILE_INOUT,
                 COLLECTION_IN,
                 COLLECTION_OUT,
                 COLLECTION_INOUT,
         ):
             if not isinstance(v, dict):
                 raise ExaquteException(
                     "Argument '{}' has invalid value".format(k))
Exemplo n.º 6
0
def _delete_object(obj):
    _check_init()
    t = type(obj)
    if t is list:
        for o in obj:
            _delete_object(o)
    elif t is ValueWrapper:
        if not obj.keep:
            raise ExaquteException(
                "Deleting non-keeped object, object created at {}".format(
                    obj.traceback))
        if obj.deleted:
            raise ExaquteException(
                "Deleting already deleted object, object created at {}".format(
                    obj.traceback))
        obj.deleted = True
    else:
        if not isinstance(obj, (bool, int, float, str)):
            if not _check_accessed(obj):
                raise ExaquteException(
                    "delete_object called on non-task value, got {!r}".format(
                        obj) + " type " + str(t))
            else:
                _delete_accessed(obj)
Exemplo n.º 7
0
def constraint(computing_units=1):
    if isinstance(computing_units, str):
        try:
            # can be cast to int
            computing_units = int(computing_units)
        except Exception:
            if computing_units.startswith("$"):
                env_var = (computing_units.replace("$", "").replace(
                    "{", "").replace("}", ""))
                try:
                    computing_units = int(os.environ[env_var])
                except Exception:
                    raise ExaquteException(
                        "Environment var: " + env_var +
                        " not defined or can't be cast to int ")
    assert isinstance(computing_units, int) and computing_units > 0
    return lambda x: x
Exemplo n.º 8
0
def get_value_from_remote(obj):
    _check_init()
    _submit_point()
    t = type(obj)
    if t is list:
        return [get_value_from_remote(o) for o in obj]
    if t is ValueWrapper:
        if not obj.keep:
            raise ExaquteException(
                "get_value_from_remote called on not keeped object, object created at {}"
                .format(obj.traceback))
        return obj.unwrap_value()
    else:
        if isinstance(obj, (int, bool, float, str)):
            return obj
        else:
            if not _check_accessed(obj):
                print(
                    "WARN: get_value_from_remote called on non-task value, got {!r}"
                    .format(obj))
            else:
                _delete_accessed(obj)
            return obj
Exemplo n.º 9
0
def _check_init():
    if not _exaqute_inited:
        raise ExaquteException("Exaqute call before init")