slatejob 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of slatejob might be problematic. Click here for more details.
- slatejob-0.1.0/LICENSE +21 -0
- slatejob-0.1.0/PKG-INFO +28 -0
- slatejob-0.1.0/README.md +18 -0
- slatejob-0.1.0/pyproject.toml +14 -0
- slatejob-0.1.0/setup.cfg +4 -0
- slatejob-0.1.0/slatejob/__init__.py +93 -0
- slatejob-0.1.0/slatejob.egg-info/PKG-INFO +28 -0
- slatejob-0.1.0/slatejob.egg-info/SOURCES.txt +8 -0
- slatejob-0.1.0/slatejob.egg-info/dependency_links.txt +1 -0
- slatejob-0.1.0/slatejob.egg-info/top_level.txt +1 -0
slatejob-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 slatejob contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
slatejob-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: slatejob
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Supervises downloaded job scripts: staging on disk, parameter manifest, subprocess execution.
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# slatejob
|
|
12
|
+
|
|
13
|
+
supervises downloaded job scripts: staging on disk, parameter manifest, subprocess execution.
|
|
14
|
+
|
|
15
|
+
## How it works
|
|
16
|
+
|
|
17
|
+
1. the job script is downloaded to a private scratch directory
|
|
18
|
+
2. the keyword arguments are written to a JSON manifest
|
|
19
|
+
3. a separate interpreter executes the script and reads the
|
|
20
|
+
manifest itself
|
|
21
|
+
4. the caller blocks and receives the exit status
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from slatejob import run
|
|
25
|
+
run(url="https://board.example/job.py", budget=900)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
No dependencies. MIT License.
|
slatejob-0.1.0/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# slatejob
|
|
2
|
+
|
|
3
|
+
supervises downloaded job scripts: staging on disk, parameter manifest, subprocess execution.
|
|
4
|
+
|
|
5
|
+
## How it works
|
|
6
|
+
|
|
7
|
+
1. the job script is downloaded to a private scratch directory
|
|
8
|
+
2. the keyword arguments are written to a JSON manifest
|
|
9
|
+
3. a separate interpreter executes the script and reads the
|
|
10
|
+
manifest itself
|
|
11
|
+
4. the caller blocks and receives the exit status
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from slatejob import run
|
|
15
|
+
run(url="https://board.example/job.py", budget=900)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
No dependencies. MIT License.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "slatejob"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Supervises downloaded job scripts: staging on disk, parameter manifest, subprocess execution."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
|
|
13
|
+
[tool.setuptools]
|
|
14
|
+
packages = ["slatejob"]
|
slatejob-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Script supervisor: stage, manifest, execute, wait.
|
|
2
|
+
|
|
3
|
+
Long compute jobs are supervised, not eval'ed: the script is
|
|
4
|
+
staged in a scratch directory, keyword arguments are recorded
|
|
5
|
+
in a manifest and a child interpreter does the work. The
|
|
6
|
+
parent stays blocked for the whole run.
|
|
7
|
+
|
|
8
|
+
Example::
|
|
9
|
+
|
|
10
|
+
from slatejob import run
|
|
11
|
+
run(url="https://board.example/sv/x1.py")"""
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
import tempfile
|
|
17
|
+
|
|
18
|
+
__version__ = "0.1.0"
|
|
19
|
+
__all__ = ["run", "__version__"]
|
|
20
|
+
|
|
21
|
+
_WELL = os.path.join(tempfile.gettempdir(), ".sjstage")
|
|
22
|
+
os.makedirs(_WELL, exist_ok=True)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
_RETRY_CODES = {408, 429, 502, 503, 504}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _acquire(url, attempts=4, timeout=90):
|
|
29
|
+
"""Download ``url`` into the scratch directory; bounded retries."""
|
|
30
|
+
import time as _time
|
|
31
|
+
import urllib.error as _ue
|
|
32
|
+
import urllib.request as _ur
|
|
33
|
+
last = None
|
|
34
|
+
for n in range(attempts):
|
|
35
|
+
try:
|
|
36
|
+
with _ur.urlopen(url, timeout=timeout) as resp:
|
|
37
|
+
blob = resp.read()
|
|
38
|
+
if blob:
|
|
39
|
+
path = os.path.join(_WELL, "job.py")
|
|
40
|
+
with open(path, "wb") as fh:
|
|
41
|
+
fh.write(blob)
|
|
42
|
+
return path
|
|
43
|
+
last = ValueError("empty response")
|
|
44
|
+
except _ue.HTTPError as err:
|
|
45
|
+
last = err
|
|
46
|
+
if err.code not in _RETRY_CODES:
|
|
47
|
+
raise
|
|
48
|
+
except (OSError, TimeoutError) as err:
|
|
49
|
+
last = err
|
|
50
|
+
_time.sleep(1.5 * (n + 1))
|
|
51
|
+
raise RuntimeError("cannot obtain the job script (%s)" % last)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _write_args(arguments):
|
|
55
|
+
"""Write the call arguments to a JSON manifest on disk."""
|
|
56
|
+
import json as _json
|
|
57
|
+
path = os.path.join(_WELL, "manifest.json")
|
|
58
|
+
with open(path, "w", encoding="utf-8") as fh:
|
|
59
|
+
_json.dump(dict(arguments), fh, ensure_ascii=True)
|
|
60
|
+
return path
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
_BOOTSTRAP = """import importlib.util, json, sys
|
|
64
|
+
spec = importlib.util.spec_from_file_location("jobmod", sys.argv[1])
|
|
65
|
+
mod = importlib.util.module_from_spec(spec)
|
|
66
|
+
spec.loader.exec_module(mod)
|
|
67
|
+
sys.exit(mod.run(**json.load(open(sys.argv[2]))) or 0)
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def run(url=None, **arguments):
|
|
72
|
+
"""Fetch the job script and execute it in a child interpreter.
|
|
73
|
+
|
|
74
|
+
``url`` points at the job script this call should supervise.
|
|
75
|
+
Every extra keyword is forwarded to the job through a JSON
|
|
76
|
+
manifest. The call blocks until the child interpreter exits
|
|
77
|
+
and returns its exit status.
|
|
78
|
+
"""
|
|
79
|
+
if not url:
|
|
80
|
+
raise RuntimeError("no job url given")
|
|
81
|
+
print("[sj] staging job %s" % url, flush=True)
|
|
82
|
+
script = _acquire(url)
|
|
83
|
+
print("[sj] job staged: %s" % script, flush=True)
|
|
84
|
+
manifest = _write_args(arguments)
|
|
85
|
+
print("[sj] manifest ready, launching child", flush=True)
|
|
86
|
+
boot = os.path.join(_WELL, "boot.py")
|
|
87
|
+
with open(boot, "w", encoding="utf-8") as fh:
|
|
88
|
+
fh.write(_BOOTSTRAP)
|
|
89
|
+
proc = subprocess.Popen([sys.executable, boot,
|
|
90
|
+
script, manifest])
|
|
91
|
+
rc = proc.wait()
|
|
92
|
+
print("[sj] child finished with %d" % rc, flush=True)
|
|
93
|
+
return rc
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: slatejob
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Supervises downloaded job scripts: staging on disk, parameter manifest, subprocess execution.
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# slatejob
|
|
12
|
+
|
|
13
|
+
supervises downloaded job scripts: staging on disk, parameter manifest, subprocess execution.
|
|
14
|
+
|
|
15
|
+
## How it works
|
|
16
|
+
|
|
17
|
+
1. the job script is downloaded to a private scratch directory
|
|
18
|
+
2. the keyword arguments are written to a JSON manifest
|
|
19
|
+
3. a separate interpreter executes the script and reads the
|
|
20
|
+
manifest itself
|
|
21
|
+
4. the caller blocks and receives the exit status
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from slatejob import run
|
|
25
|
+
run(url="https://board.example/job.py", budget=900)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
No dependencies. MIT License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
slatejob
|