Sample
greenlet 3.2.4: coroutine task switching with greenlet
Verified sample for pypi greenlet 3.2.4: coroutine task switching with greenlet. The contract ran on python 3.12 · linux alpine/x64 · docker and passed.
sha256:18a8ff77421e3e57c240e216e3bbb1aa8726f9b2077e36c5e46f023d16a27a1e
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
python linux 24 · ubuntu · glibc 2.39 x64 python python pip
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-19 |
Case
HOW- Goal
- coroutine task switching with greenlet
- Packages
- Symbols
-
- greenlet.greenlet
- Environment
- python
- Created
- 2026-08-19T18:52:48Z
Contract
- greenlet coroutines switch execution back and forth passing values and tracking lifecycle state
Files
- PROMPT.md
- csx.json
- requirements.txt
- sample.py
- spec.json
- test/contract.py
Source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: coroutine task switching with greenlet
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:pypi/greenlet@3.2.4
Demonstrate these symbols/APIs:
- greenlet.greenlet
Required runtime conditions:
- ecosystem: pypi
- language: python
- packageManager: pip
- runtime: python
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:f941671c65edbc00f8712d84e791b5651faceeb36498b4b609ebff85a08278e9","contract":["greenlet coroutines switch execution back and forth passing values and tracking lifecycle state"],"goal":"coroutine task switching with greenlet","kind":"HOW","packages":["pkg:pypi/greenlet@3.2.4"],"schemaVersion":1,"symbols":["greenlet.greenlet"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","language":"python","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","runtime":"python","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/greenlet@3.2.4"],"schemaVersion":1,"symbols":["greenlet.greenlet"],"verifierAdapter":"python@1"}
greenlet==3.2.4
from greenlet import greenlet
def run_cooperative_tasks():
events = []
def task_alpha(initial_msg):
events.append(f"alpha_started:{initial_msg}")
beta_reply = gr_beta.switch("from_alpha_step1")
events.append(f"alpha_resumed:{beta_reply}")
return "alpha_finished"
def task_beta(msg_from_alpha):
events.append(f"beta_started:{msg_from_alpha}")
alpha_reply = gr_alpha.switch("from_beta_step1")
events.append(f"beta_resumed:{alpha_reply}")
return "beta_finished"
gr_alpha = greenlet(task_alpha)
gr_beta = greenlet(task_beta)
res_a = gr_alpha.switch("init")
res_b = gr_beta.switch("continue_beta")
return {
"alpha_result": res_a,
"beta_result": res_b,
"events": events,
"alpha_dead": gr_alpha.dead,
"beta_dead": gr_beta.dead,
}
if __name__ == "__main__":
result = run_cooperative_tasks()
print("Cooperative execution:", result)
{
"schemaVersion": 1,
"goal": "coroutine task switching with greenlet",
"kind": "HOW",
"packages": [
"pkg:pypi/greenlet@3.2.4"
],
"symbols": [
"greenlet.greenlet"
],
"runtimeConditions": {
"ecosystem": "pypi",
"language": "python",
"packageManager": "pip",
"runtime": "python"
}
}
import sys
from greenlet import greenlet
def test_greenlet_switching():
events = []
def coroutine_a(val):
events.append(f"a_start:{val}")
resp = g_b.switch("msg_from_a")
events.append(f"a_resume:{resp}")
return "result_a"
def coroutine_b(val):
events.append(f"b_start:{val}")
resp = g_a.switch("msg_from_b")
events.append(f"b_resume:{resp}")
return "result_b"
g_a = greenlet(coroutine_a)
g_b = greenlet(coroutine_b)
assert not g_a.dead
assert not g_b.dead
res_a = g_a.switch("init_a")
assert res_a == "result_a"
assert g_a.dead
assert not g_b.dead
assert events == ["a_start:init_a", "b_start:msg_from_a", "a_resume:msg_from_b"]
res_b = g_b.switch("resume_b")
assert res_b == "result_b"
assert g_b.dead
assert events == [
"a_start:init_a",
"b_start:msg_from_a",
"a_resume:msg_from_b",
"b_resume:resume_b",
]
def main():
test_greenlet_switching()
print("Contract verification passed.")
if __name__ == "__main__":
main()
Origin Seeder
anonymous