vlambda 0.2.0__tar.gz → 0.2.2__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.
- {vlambda-0.2.0 → vlambda-0.2.2}/PKG-INFO +36 -12
- {vlambda-0.2.0 → vlambda-0.2.2}/README.md +35 -11
- {vlambda-0.2.0 → vlambda-0.2.2}/pyproject.toml +1 -1
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/__main__.py +21 -16
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/assets.py +1 -1
- vlambda-0.2.2/python/vlambda/pool.py +647 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/runner.py +49 -1
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/sandbox.py +6 -3
- vlambda-0.2.2/python/vlambda/sandbox_os.py +294 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/src/vlambda_native.v +72 -11
- {vlambda-0.2.0 → vlambda-0.2.2}/tests/test_unit.py +36 -4
- {vlambda-0.2.0 → vlambda-0.2.2}/tests/test_vlambda.py +168 -2
- {vlambda-0.2.0 → vlambda-0.2.2}/vcraft.toml +1 -1
- vlambda-0.2.0/python/vlambda/pool.py +0 -285
- {vlambda-0.2.0 → vlambda-0.2.2}/LICENSE +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/__init__.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/auth.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/cache.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/dbpool.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/metrics.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/packages.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/project.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/py.typed +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/request.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/reset.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/shared_cache.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/tasks.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/python/vlambda/transfer.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/tests/conftest.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/v.mod +0 -0
- {vlambda-0.2.0 → vlambda-0.2.2}/vcraft_build.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: vlambda
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: An ASGI-like server for Python lambdas, written in V.
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: >=3.14
|
|
@@ -28,12 +28,12 @@ POST that code to `/vlambda` and it becomes `GET /f/<slug>` instantly.
|
|
|
28
28
|
|
|
29
29
|
## Features
|
|
30
30
|
|
|
31
|
-
- **No cold starts** —
|
|
31
|
+
- **No cold starts in persistent mode** — Docker uses a fresh Landlock process per invocation, which adds a small startup cost
|
|
32
32
|
- **Fast** — ~3,000 req/s (concurrent, free-threaded Python), ~0.3ms/req
|
|
33
33
|
- **Auth** — JWT-based authentication with per-user ownership
|
|
34
34
|
- **Web UI** — Dashboard for managing lambdas, code editor, metrics
|
|
35
35
|
- **Async invocation** — Fire-and-forget with task tracking
|
|
36
|
-
- **Sandbox** —
|
|
36
|
+
- **Sandbox** — Landlock + seccomp in Docker, plus restricted Python builtins and blocked modules
|
|
37
37
|
- **Metrics** — Prometheus-compatible + Chart.js dashboard
|
|
38
38
|
- **Per-lambda method** — GET, POST, PUT, PATCH, DELETE
|
|
39
39
|
- **Naming** — Human-readable names for lambdas
|
|
@@ -102,8 +102,13 @@ token with `DELETE /tokens/<id>`. Tokens do not expire.
|
|
|
102
102
|
## Docker + Dokploy
|
|
103
103
|
|
|
104
104
|
The repository includes a production image (`Dockerfile`, installs from PyPI) and
|
|
105
|
-
a development image (`Dockerfile.dev`, builds the local wheel). Both
|
|
106
|
-
|
|
105
|
+
a development image (`Dockerfile.dev`, builds the local wheel). Both use a
|
|
106
|
+
free-threaded Python 3.14 venv, run each invocation in a Landlock + seccomp
|
|
107
|
+
sandbox and expose plain HTTP on port `8080`; Dokploy (or another proxy) handles
|
|
108
|
+
TLS and the public domain.
|
|
109
|
+
|
|
110
|
+
The sandbox needs no extra Docker flags, capabilities or host sysctl changes.
|
|
111
|
+
It requires a Linux kernel with Landlock (5.13+; Ubuntu 22.04+, Debian 12+).
|
|
107
112
|
|
|
108
113
|
```bash
|
|
109
114
|
export VLAMBDA_SECRET="$(openssl rand -hex 32)"
|
|
@@ -115,7 +120,7 @@ With Dokploy, create an application from the image, map the domain to container
|
|
|
115
120
|
port `8080`, and set `VLAMBDA_SECRET` and `VLAMBDA_ADMIN_TOKEN`. Dokploy terminates
|
|
116
121
|
TLS, so the container does not manage certificates.
|
|
117
122
|
|
|
118
|
-
See `docker/README.md` for details, limits and the
|
|
123
|
+
See `docker/README.md` for details, limits and the reset command.
|
|
119
124
|
|
|
120
125
|
## CLI Options
|
|
121
126
|
|
|
@@ -131,12 +136,15 @@ See `docker/README.md` for details, limits and the weekly reset command.
|
|
|
131
136
|
| `--cors_origin` | `VLAMBDA_CORS` | * | CORS allowed origin |
|
|
132
137
|
| `--cert` | `VLAMBDA_CERT` | | TLS certificate path |
|
|
133
138
|
| `--key` | `VLAMBDA_KEY` | | TLS key path |
|
|
139
|
+
| | `VLAMBDA_REGISTRATION` | 1 | Allow public registration (`0` disables it) |
|
|
134
140
|
|
|
135
141
|
## API
|
|
136
142
|
|
|
137
143
|
### Authentication
|
|
138
|
-
- `
|
|
144
|
+
- `GET /config` — Public runtime flags (whether registration is open)
|
|
145
|
+
- `POST /register` — Register user (body: `username:password`); returns `403` when registration is disabled
|
|
139
146
|
- `POST /login` — Login (body: `username:password`) → JWT token
|
|
147
|
+
- `POST /admin/users` — Create a user with `X-Admin-Token` and body `username:password` (for closed registration)
|
|
140
148
|
|
|
141
149
|
### Lambdas (requires auth)
|
|
142
150
|
- `POST /vlambda?method=GET&name=my-lambda` — Create lambda (body: Python code)
|
|
@@ -238,10 +246,26 @@ The `request` object has: `method`, `path`, `query_string`, `headers`, `body`.
|
|
|
238
246
|
|
|
239
247
|
Safe builtins: `abs`, `all`, `any`, `bool`, `dict`, `enumerate`, `filter`, `float`, `int`, `len`, `list`, `map`, `max`, `min`, `range`, `reversed`, `round`, `set`, `sorted`, `str`, `sum`, `tuple`, `zip`, `print`, etc.
|
|
240
248
|
|
|
241
|
-
Blocked modules: `os`, `subprocess`, `sys`, `importlib`, `ctypes`, `socket`, `urllib`, `http`, `shutil`, `pathlib`, `io`, `pickle`, `marshal`, etc.
|
|
249
|
+
Blocked modules: `os`, `posix`, `subprocess`, `sys`, `importlib`, `ctypes`, `socket`, `_socket`, `urllib`, `http`, `shutil`, `pathlib`, `io`, `pickle`, `marshal`, `resource`, `fcntl`, `mmap`, `sqlite3`, etc.
|
|
242
250
|
|
|
243
251
|
Safe modules: `json`, `math`, `re`, `datetime`, `collections`, `itertools`, `functools`, `hashlib`, `base64`, `string`, `random`, `statistics`, etc.
|
|
244
252
|
|
|
253
|
+
### Security
|
|
254
|
+
|
|
255
|
+
User code runs in a fresh runner process confined with Landlock and seccomp.
|
|
256
|
+
Landlock limits the filesystem to `/opt`, `/usr`, `/lib`, `/etc`, the current
|
|
257
|
+
project/vendor and a private temporary directory; `/data`, `/proc`, `/sys` and
|
|
258
|
+
the rest of the server cannot be read or listed. seccomp blocks network, cross-process
|
|
259
|
+
signals, `ptrace`, `mount`, namespace changes and similar syscalls. Resource
|
|
260
|
+
limits are applied too, and each invocation gets a fresh process.
|
|
261
|
+
|
|
262
|
+
The Docker image keeps public registration open by default for toy deployments.
|
|
263
|
+
Set `VLAMBDA_REGISTRATION=0` to close it and create users with
|
|
264
|
+
`POST /admin/users` instead. A daily data reset removes state, but it does not
|
|
265
|
+
undo a kernel-level escape. Keep this deployment disposable and do not store
|
|
266
|
+
valuable secrets in it; for stronger isolation use gVisor, Firecracker or one
|
|
267
|
+
container per tenant.
|
|
268
|
+
|
|
245
269
|
## Web UI
|
|
246
270
|
|
|
247
271
|
Open http://localhost:8080/ in your browser for the dashboard:
|
|
@@ -261,20 +285,20 @@ Open http://localhost:8080/ in your browser for the dashboard:
|
|
|
261
285
|
The demo can be wiped with:
|
|
262
286
|
|
|
263
287
|
```bash
|
|
264
|
-
python -m vlambda reset --yes --url http://127.0.0.1:
|
|
288
|
+
python -m vlambda reset --yes --url http://127.0.0.1:8080 --token "$VLAMBDA_ADMIN_TOKEN"
|
|
265
289
|
```
|
|
266
290
|
|
|
267
|
-
For
|
|
291
|
+
For a disposable demo, run it from cron every day:
|
|
268
292
|
|
|
269
293
|
```cron
|
|
270
|
-
0
|
|
294
|
+
0 3 * * * docker exec -e VLAMBDA_ADMIN_TOKEN="..." <container> /opt/venv/bin/python -m vlambda reset --yes --url http://127.0.0.1:8080
|
|
271
295
|
```
|
|
272
296
|
|
|
273
297
|
## Performance
|
|
274
298
|
|
|
275
299
|
| Metric | Value |
|
|
276
300
|
|--------|-------|
|
|
277
|
-
| Cold start | 0ms
|
|
301
|
+
| Cold start | 0ms in persistent mode; fresh sandbox process in Docker |
|
|
278
302
|
| Warm invocation | ~0.3ms |
|
|
279
303
|
| Throughput (concurrent, free-threaded) | ~3,000 req/s |
|
|
280
304
|
| Throughput (response cache hits) | ~100x faster |
|
|
@@ -17,12 +17,12 @@ POST that code to `/vlambda` and it becomes `GET /f/<slug>` instantly.
|
|
|
17
17
|
|
|
18
18
|
## Features
|
|
19
19
|
|
|
20
|
-
- **No cold starts** —
|
|
20
|
+
- **No cold starts in persistent mode** — Docker uses a fresh Landlock process per invocation, which adds a small startup cost
|
|
21
21
|
- **Fast** — ~3,000 req/s (concurrent, free-threaded Python), ~0.3ms/req
|
|
22
22
|
- **Auth** — JWT-based authentication with per-user ownership
|
|
23
23
|
- **Web UI** — Dashboard for managing lambdas, code editor, metrics
|
|
24
24
|
- **Async invocation** — Fire-and-forget with task tracking
|
|
25
|
-
- **Sandbox** —
|
|
25
|
+
- **Sandbox** — Landlock + seccomp in Docker, plus restricted Python builtins and blocked modules
|
|
26
26
|
- **Metrics** — Prometheus-compatible + Chart.js dashboard
|
|
27
27
|
- **Per-lambda method** — GET, POST, PUT, PATCH, DELETE
|
|
28
28
|
- **Naming** — Human-readable names for lambdas
|
|
@@ -91,8 +91,13 @@ token with `DELETE /tokens/<id>`. Tokens do not expire.
|
|
|
91
91
|
## Docker + Dokploy
|
|
92
92
|
|
|
93
93
|
The repository includes a production image (`Dockerfile`, installs from PyPI) and
|
|
94
|
-
a development image (`Dockerfile.dev`, builds the local wheel). Both
|
|
95
|
-
|
|
94
|
+
a development image (`Dockerfile.dev`, builds the local wheel). Both use a
|
|
95
|
+
free-threaded Python 3.14 venv, run each invocation in a Landlock + seccomp
|
|
96
|
+
sandbox and expose plain HTTP on port `8080`; Dokploy (or another proxy) handles
|
|
97
|
+
TLS and the public domain.
|
|
98
|
+
|
|
99
|
+
The sandbox needs no extra Docker flags, capabilities or host sysctl changes.
|
|
100
|
+
It requires a Linux kernel with Landlock (5.13+; Ubuntu 22.04+, Debian 12+).
|
|
96
101
|
|
|
97
102
|
```bash
|
|
98
103
|
export VLAMBDA_SECRET="$(openssl rand -hex 32)"
|
|
@@ -104,7 +109,7 @@ With Dokploy, create an application from the image, map the domain to container
|
|
|
104
109
|
port `8080`, and set `VLAMBDA_SECRET` and `VLAMBDA_ADMIN_TOKEN`. Dokploy terminates
|
|
105
110
|
TLS, so the container does not manage certificates.
|
|
106
111
|
|
|
107
|
-
See `docker/README.md` for details, limits and the
|
|
112
|
+
See `docker/README.md` for details, limits and the reset command.
|
|
108
113
|
|
|
109
114
|
## CLI Options
|
|
110
115
|
|
|
@@ -120,12 +125,15 @@ See `docker/README.md` for details, limits and the weekly reset command.
|
|
|
120
125
|
| `--cors_origin` | `VLAMBDA_CORS` | * | CORS allowed origin |
|
|
121
126
|
| `--cert` | `VLAMBDA_CERT` | | TLS certificate path |
|
|
122
127
|
| `--key` | `VLAMBDA_KEY` | | TLS key path |
|
|
128
|
+
| | `VLAMBDA_REGISTRATION` | 1 | Allow public registration (`0` disables it) |
|
|
123
129
|
|
|
124
130
|
## API
|
|
125
131
|
|
|
126
132
|
### Authentication
|
|
127
|
-
- `
|
|
133
|
+
- `GET /config` — Public runtime flags (whether registration is open)
|
|
134
|
+
- `POST /register` — Register user (body: `username:password`); returns `403` when registration is disabled
|
|
128
135
|
- `POST /login` — Login (body: `username:password`) → JWT token
|
|
136
|
+
- `POST /admin/users` — Create a user with `X-Admin-Token` and body `username:password` (for closed registration)
|
|
129
137
|
|
|
130
138
|
### Lambdas (requires auth)
|
|
131
139
|
- `POST /vlambda?method=GET&name=my-lambda` — Create lambda (body: Python code)
|
|
@@ -227,10 +235,26 @@ The `request` object has: `method`, `path`, `query_string`, `headers`, `body`.
|
|
|
227
235
|
|
|
228
236
|
Safe builtins: `abs`, `all`, `any`, `bool`, `dict`, `enumerate`, `filter`, `float`, `int`, `len`, `list`, `map`, `max`, `min`, `range`, `reversed`, `round`, `set`, `sorted`, `str`, `sum`, `tuple`, `zip`, `print`, etc.
|
|
229
237
|
|
|
230
|
-
Blocked modules: `os`, `subprocess`, `sys`, `importlib`, `ctypes`, `socket`, `urllib`, `http`, `shutil`, `pathlib`, `io`, `pickle`, `marshal`, etc.
|
|
238
|
+
Blocked modules: `os`, `posix`, `subprocess`, `sys`, `importlib`, `ctypes`, `socket`, `_socket`, `urllib`, `http`, `shutil`, `pathlib`, `io`, `pickle`, `marshal`, `resource`, `fcntl`, `mmap`, `sqlite3`, etc.
|
|
231
239
|
|
|
232
240
|
Safe modules: `json`, `math`, `re`, `datetime`, `collections`, `itertools`, `functools`, `hashlib`, `base64`, `string`, `random`, `statistics`, etc.
|
|
233
241
|
|
|
242
|
+
### Security
|
|
243
|
+
|
|
244
|
+
User code runs in a fresh runner process confined with Landlock and seccomp.
|
|
245
|
+
Landlock limits the filesystem to `/opt`, `/usr`, `/lib`, `/etc`, the current
|
|
246
|
+
project/vendor and a private temporary directory; `/data`, `/proc`, `/sys` and
|
|
247
|
+
the rest of the server cannot be read or listed. seccomp blocks network, cross-process
|
|
248
|
+
signals, `ptrace`, `mount`, namespace changes and similar syscalls. Resource
|
|
249
|
+
limits are applied too, and each invocation gets a fresh process.
|
|
250
|
+
|
|
251
|
+
The Docker image keeps public registration open by default for toy deployments.
|
|
252
|
+
Set `VLAMBDA_REGISTRATION=0` to close it and create users with
|
|
253
|
+
`POST /admin/users` instead. A daily data reset removes state, but it does not
|
|
254
|
+
undo a kernel-level escape. Keep this deployment disposable and do not store
|
|
255
|
+
valuable secrets in it; for stronger isolation use gVisor, Firecracker or one
|
|
256
|
+
container per tenant.
|
|
257
|
+
|
|
234
258
|
## Web UI
|
|
235
259
|
|
|
236
260
|
Open http://localhost:8080/ in your browser for the dashboard:
|
|
@@ -250,20 +274,20 @@ Open http://localhost:8080/ in your browser for the dashboard:
|
|
|
250
274
|
The demo can be wiped with:
|
|
251
275
|
|
|
252
276
|
```bash
|
|
253
|
-
python -m vlambda reset --yes --url http://127.0.0.1:
|
|
277
|
+
python -m vlambda reset --yes --url http://127.0.0.1:8080 --token "$VLAMBDA_ADMIN_TOKEN"
|
|
254
278
|
```
|
|
255
279
|
|
|
256
|
-
For
|
|
280
|
+
For a disposable demo, run it from cron every day:
|
|
257
281
|
|
|
258
282
|
```cron
|
|
259
|
-
0
|
|
283
|
+
0 3 * * * docker exec -e VLAMBDA_ADMIN_TOKEN="..." <container> /opt/venv/bin/python -m vlambda reset --yes --url http://127.0.0.1:8080
|
|
260
284
|
```
|
|
261
285
|
|
|
262
286
|
## Performance
|
|
263
287
|
|
|
264
288
|
| Metric | Value |
|
|
265
289
|
|--------|-------|
|
|
266
|
-
| Cold start | 0ms
|
|
290
|
+
| Cold start | 0ms in persistent mode; fresh sandbox process in Docker |
|
|
267
291
|
| Warm invocation | ~0.3ms |
|
|
268
292
|
| Throughput (concurrent, free-threaded) | ~3,000 req/s |
|
|
269
293
|
| Throughput (response cache hits) | ~100x faster |
|
|
@@ -54,7 +54,7 @@ def main() -> None:
|
|
|
54
54
|
from vlambda.auth import verify_token, create_token, hash_password, check_password
|
|
55
55
|
import sqlite3
|
|
56
56
|
from vlambda.request import Request
|
|
57
|
-
from vlambda_native import start_server, db_init, register_pool, register_auth_verifier, register_auth_register, register_auth_login, configure, register_validate_code, register_ui_html, register_get_asset, register_get_project_json, register_save_project_json, register_list_versions, register_list_aliases, register_admin_reset, register_list_packages, register_install_packages, register_create_task, register_get_task, register_record_metric, register_query_metrics, register_query_stats, register_query_summary, register_query_aggregate, register_query_logs, register_delete_metrics, register_delete_logs, register_export_metrics, register_pool_stats, register_run_project, register_create_project, register_delete_project, register_schedule_delete, register_get_dlq, register_export_lambda, register_import_lambda, register_duplicate_lambda, set_overloaded
|
|
57
|
+
from vlambda_native import start_server, db_init, register_pool, register_auth_verifier, register_auth_register, register_auth_login, configure, register_validate_code, register_ui_html, register_get_asset, register_get_project_json, register_save_project_json, register_list_versions, register_list_aliases, register_admin_reset, register_admin_create_user, register_list_packages, register_install_packages, register_create_task, register_get_task, register_record_metric, register_query_metrics, register_query_stats, register_query_summary, register_query_aggregate, register_query_logs, register_delete_metrics, register_delete_logs, register_export_metrics, register_pool_stats, register_run_project, register_create_project, register_delete_project, register_schedule_delete, register_get_dlq, register_export_lambda, register_import_lambda, register_duplicate_lambda, set_overloaded
|
|
58
58
|
|
|
59
59
|
if not db_init(args.sqlite_path):
|
|
60
60
|
print("Failed to initialize database", file=sys.stderr)
|
|
@@ -69,11 +69,12 @@ def main() -> None:
|
|
|
69
69
|
|
|
70
70
|
metrics_enabled = os.environ.get("VLAMBDA_METRICS_ENABLED", "1") == "1"
|
|
71
71
|
metrics_sample = int(os.environ.get("VLAMBDA_METRICS_SAMPLE", "1"))
|
|
72
|
+
registration_enabled = os.environ.get("VLAMBDA_REGISTRATION", "1") == "1"
|
|
72
73
|
|
|
73
74
|
configure(
|
|
74
75
|
args.max_body_size, args.rate_limit, args.invoke_timeout,
|
|
75
76
|
args.max_memory_mb, args.cors_origin, args.cert, args.key,
|
|
76
|
-
metrics_enabled, metrics_sample,
|
|
77
|
+
metrics_enabled, metrics_sample, registration_enabled,
|
|
77
78
|
)
|
|
78
79
|
|
|
79
80
|
metrics_db = os.environ.get("VLAMBDA_METRICS_DB", args.sqlite_path.replace(".db", "_metrics.db"))
|
|
@@ -142,6 +143,8 @@ def main() -> None:
|
|
|
142
143
|
vendor_dir = candidate
|
|
143
144
|
except Exception:
|
|
144
145
|
pass
|
|
146
|
+
if not timeout:
|
|
147
|
+
timeout = args.invoke_timeout
|
|
145
148
|
result = pool.execute(code, method, path, query, body, timeout, memory_mb, vendor_dir, request_id, slug)
|
|
146
149
|
if isinstance(result, str):
|
|
147
150
|
payload = result
|
|
@@ -237,6 +240,16 @@ def main() -> None:
|
|
|
237
240
|
|
|
238
241
|
register_admin_reset(_admin_reset)
|
|
239
242
|
|
|
243
|
+
def _admin_create_user(token, username, password):
|
|
244
|
+
if not _admin_token_ok(token):
|
|
245
|
+
return json.dumps({"error": "forbidden"})
|
|
246
|
+
uid = _auth_register(username, password)
|
|
247
|
+
if uid < 0:
|
|
248
|
+
return json.dumps({"error": "user already exists"})
|
|
249
|
+
return json.dumps({"user_id": uid})
|
|
250
|
+
|
|
251
|
+
register_admin_create_user(_admin_create_user)
|
|
252
|
+
|
|
240
253
|
from vlambda.packages import list_for as _list_packages, install_for as _install_packages
|
|
241
254
|
|
|
242
255
|
def _list_packages_cb(slug, kind, project_dir):
|
|
@@ -369,25 +382,17 @@ def main() -> None:
|
|
|
369
382
|
|
|
370
383
|
from vlambda.project import create_project as _create_project, execute_project as _execute_project, delete_project as _delete_project_impl, schedule_delete as _schedule_delete_impl
|
|
371
384
|
|
|
372
|
-
def _run_project(project_dir, entrypoint,
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
method=request_dict.get("method", "GET"),
|
|
376
|
-
path=request_dict.get("path", "/"),
|
|
377
|
-
query_string=request_dict.get("query_string", ""),
|
|
378
|
-
headers={},
|
|
379
|
-
body=request_dict.get("body", b""),
|
|
380
|
-
)
|
|
385
|
+
def _run_project(project_dir, entrypoint, method, path, query, body):
|
|
386
|
+
import json
|
|
387
|
+
timeout = args.invoke_timeout
|
|
381
388
|
try:
|
|
382
|
-
result =
|
|
383
|
-
import json
|
|
389
|
+
result = pool.execute_project(project_dir, entrypoint, method, path, query, body, timeout=timeout)
|
|
384
390
|
if isinstance(result, str):
|
|
385
391
|
return result
|
|
386
392
|
if isinstance(result, (dict, list)):
|
|
387
393
|
return json.dumps(result)
|
|
388
394
|
return str(result)
|
|
389
395
|
except Exception as e:
|
|
390
|
-
import json
|
|
391
396
|
return json.dumps({"error": f"{type(e).__name__}: {e}"})
|
|
392
397
|
|
|
393
398
|
def _delete_project(project_dir):
|
|
@@ -478,8 +483,8 @@ def main() -> None:
|
|
|
478
483
|
if args.max_memory_mb > 0:
|
|
479
484
|
import threading, time, resource
|
|
480
485
|
# A hard RLIMIT_AS for the whole process starves V/Python threads and
|
|
481
|
-
# mmap. Use
|
|
482
|
-
# enabled explicitly for constrained environments.
|
|
486
|
+
# mmap. Use the Docker cgroup or the per-invocation sandbox limits
|
|
487
|
+
# instead. It can be enabled explicitly for constrained environments.
|
|
483
488
|
if os.environ.get("VLAMBDA_HARD_MEMORY_LIMIT", "0") == "1":
|
|
484
489
|
limit_bytes = args.max_memory_mb * 1024 * 1024
|
|
485
490
|
try:
|