MCPcopy Create free account
hub / github.com/It4innovations/hyperqueue / function

Method function

crates/pyhq/python/hyperqueue/job.py:100–150  ·  view source on GitHub ↗

Creates a new task that will execute the provided Python function. :param args: Positional arguments that will be passed to the Python function. :param kwargs: Keyword arguments that will be passed to the Python function. :param env: Environment variables passed to

(
        self,
        fn,
        *,
        args=(),
        kwargs=None,
        env: Optional[EnvType] = None,
        cwd: Optional[GenericPath] = None,
        stdout: Optional[Stdio] = default_stdout(),
        stderr: Optional[Stdio] = default_stderr(),
        deps: Sequence[Task] = (),
        name: Optional[str] = None,
        priority: int = 0,
        resources: Optional[Union[ResourceRequest, Sequence[ResourceRequest]]] = None,
        crash_limit: Optional[int] = None,
    )

Source from the content-addressed store, hash-verified

98 return task
99
100 def function(
101 self,
102 fn,
103 *,
104 args=(),
105 kwargs=None,
106 env: Optional[EnvType] = None,
107 cwd: Optional[GenericPath] = None,
108 stdout: Optional[Stdio] = default_stdout(),
109 stderr: Optional[Stdio] = default_stderr(),
110 deps: Sequence[Task] = (),
111 name: Optional[str] = None,
112 priority: int = 0,
113 resources: Optional[Union[ResourceRequest, Sequence[ResourceRequest]]] = None,
114 crash_limit: Optional[int] = None,
115 ) -> PythonFunction:
116 """
117 Creates a new task that will execute the provided Python function.
118
119 :param args: Positional arguments that will be passed to the Python function.
120 :param kwargs: Keyword arguments that will be passed to the Python function.
121 :param env: Environment variables passed to the executed command.
122 :param cwd: Working directory of the executed command.
123 :param stdout: Path to a file that will store the standard output of the executed command.
124 :param stderr: Path to a file that will store the standard error output of the executed
125 command.
126 :param deps: A sequence of dependencies that have to be completed first before this task
127 can start executing.
128 :param name: Name of the task.
129 :param priority: Priority of the created task.
130 :param resources: List of resource requests required by this task.
131 :param crash_limit: How many times can a worker that executes this task crash before the
132 task is considered to be failed.
133 """
134 task = PythonFunction(
135 len(self.tasks),
136 fn,
137 args=args,
138 kwargs=kwargs,
139 env=merge_envs(self.default_env, env),
140 cwd=cwd or self.default_workdir,
141 stdout=stdout,
142 stderr=stderr,
143 name=name,
144 dependencies=deps,
145 priority=priority,
146 resources=resources,
147 crash_limit=crash_limit,
148 )
149 self._add_task(task)
150 return task
151
152 def _add_task(self, task: Task):
153 self.tasks.append(task)

Callers 14

test_function_nameFunction · 0.95
test_visualizationFunction · 0.95
executeMethod · 0.95
test_submit_pyfunctionFunction · 0.80
test_function_resourcesFunction · 0.80
test_default_workdirFunction · 0.80
test_default_envFunction · 0.80

Calls 5

_add_taskMethod · 0.95
default_stdoutFunction · 0.85
default_stderrFunction · 0.85
PythonFunctionClass · 0.85
merge_envsFunction · 0.85

Tested by 13

test_function_nameFunction · 0.76
test_visualizationFunction · 0.76
test_submit_pyfunctionFunction · 0.64
test_function_resourcesFunction · 0.64
test_default_workdirFunction · 0.64
test_default_envFunction · 0.64
test_empty_stdioFunction · 0.64