Exemple
anyio 4.13.0: Event, create_memory_object_stream, create_task_group
Échantillon vérifié pour pypi anyio 4.13.0: Event, create_memory_object_stream, create_task_group. Le contrat s'est exécuté sur python 3.12 · linux…
sha256:b89e8cfd62364f84959241e0db09074a533f777958fd85b6d951777622fe345d
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 2
- Clés de signature qui l’ont compilé
- 2
Environnement déclaré
python 3.12 linux 24 · ubuntu · glibc 2.39 x64 python 3.12 python pip 24
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-20 |
| python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104… |
2026-09-07 |
Cas
HOW- Objectif
- verify pkg:pypi/anyio@4.13.0
- Paquets
- Symboles
-
- anyio.Event
- anyio.create_memory_object_stream
- anyio.create_task_group
- anyio.move_on_after
- anyio.run
- anyio.to_thread.run_sync
- Environnement
- python 3.12
- Créé
- 2026-08-20T10:11:53Z
Contrat
- anyio.run executes an async entrypoint coroutine and returns its result
- create_task_group coordinates concurrent tasks and manages their lifecycle
- create_memory_object_stream provides typed asynchronous item streaming between tasks
- move_on_after cancels execution when the allotted timeout duration expires
- Event facilitates asynchronous signaling and task coordination
- to_thread.run_sync offloads blocking synchronous execution to worker threads
Fichiers
- PROMPT.md
- csx.json
- pyproject.toml
- requirements.txt
- spec.json
- src/__init__.py
- src/sample.py
- test/contract.py
Code 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: verify pkg:pypi/anyio@4.13.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:pypi/anyio@4.13.0
Demonstrate these symbols/APIs:
- anyio.Event
- anyio.create_memory_object_stream
- anyio.create_task_group
- anyio.move_on_after
- anyio.run
- anyio.to_thread.run_sync
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:6e7eb877c090f0eb629bb3b2a7fd049d137240b79c9ec20f08141fe8d735aaa3","contract":["anyio.run executes an async entrypoint coroutine and returns its result","create_task_group coordinates concurrent tasks and manages their lifecycle","create_memory_object_stream provides typed asynchronous item streaming between tasks","move_on_after cancels execution when the allotted timeout duration expires","Event facilitates asynchronous signaling and task coordination","to_thread.run_sync offloads blocking synchronous execution to worker threads"],"goal":"verify pkg:pypi/anyio@4.13.0","kind":"HOW","packages":["pkg:pypi/anyio@4.13.0"],"schemaVersion":1,"symbols":["anyio.Event","anyio.create_memory_object_stream","anyio.create_task_group","anyio.move_on_after","anyio.run","anyio.to_thread.run_sync"]},"contractCommand":["python3","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","language":"python","libc":"glibc","libcVersion":"2.39","moduleSystem":"standard","os":"linux","osVersionBucket":"24","packageManager":"pip","packageManagerVersion":"24.0","runtime":"python","runtimeVersion":"3.12","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/anyio@4.13.0"],"schemaVersion":1,"symbols":["anyio.Event","anyio.create_memory_object_stream","anyio.create_task_group","anyio.move_on_after","anyio.run","anyio.to_thread.run_sync"],"verifierAdapter":"python@1"}
[project]
name = "anyio-sample"
version = "0.1.0"
description = "Clean-room verification sample for anyio"
requires-python = ">=3.9"
dependencies = [
"anyio==4.13.0",
"idna==3.19",
"typing-extensions==4.16.0"
]
anyio==4.13.0
idna==3.19
typing-extensions==4.16.0
{
"schemaVersion": 1,
"goal": "verify pkg:pypi/anyio@4.13.0",
"kind": "HOW",
"packages": [
"pkg:pypi/anyio@4.13.0"
],
"symbols": [
"anyio.Event",
"anyio.create_memory_object_stream",
"anyio.create_task_group",
"anyio.move_on_after",
"anyio.run",
"anyio.to_thread.run_sync"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
from .sample import (
run_entrypoint,
run_task_group_tasks,
stream_pipeline,
check_timeout_cancellation,
coordinate_with_event,
execute_in_worker_thread,
)
__all__ = [
"run_entrypoint",
"run_task_group_tasks",
"stream_pipeline",
"check_timeout_cancellation",
"coordinate_with_event",
"execute_in_worker_thread",
]
"""Clean-room demonstration of anyio 4.13.0 core features."""
import time
from typing import Any, Callable, List, Sequence, Tuple
import anyio
async def _async_multiply(value: int, factor: int) -> int:
await anyio.sleep(0.001)
return value * factor
def run_entrypoint(value: int, factor: int) -> int:
"""Executes an async coroutine using anyio.run."""
return anyio.run(_async_multiply, value, factor)
async def _concurrent_collector(inputs: Sequence[int]) -> List[int]:
results: List[int] = []
async def worker(item: int) -> None:
await anyio.sleep(0.001)
results.append(item * 10)
async with anyio.create_task_group() as tg:
for val in inputs:
tg.start_soon(worker, val)
return sorted(results)
def run_task_group_tasks(inputs: Sequence[int]) -> List[int]:
"""Runs concurrent async workers using create_task_group."""
return anyio.run(_concurrent_collector, inputs)
async def _stream_producer_consumer(items: Sequence[str]) -> List[str]:
send_stream, receive_stream = anyio.create_memory_object_stream(max_buffer_size=len(items) + 1)
collected: List[str] = []
async def producer() -> None:
async with send_stream:
for item in items:
await send_stream.send(item)
async def consumer() -> None:
async with receive_stream:
async for received_item in receive_stream:
collected.append(received_item)
async with anyio.create_task_group() as tg:
tg.start_soon(producer)
tg.start_soon(consumer)
return collected
def stream_pipeline(items: Sequence[str]) -> List[str]:
"""Demonstrates memory object stream between producer and consumer tasks."""
return anyio.run(_stream_producer_consumer, items)
async def _timeout_checker(delay: float, timeout_limit: float) -> bool:
with anyio.move_on_after(timeout_limit) as cancel_scope:
await anyio.sleep(delay)
return cancel_scope.cancelled_caught
def check_timeout_cancellation(delay: float, timeout_limit: float) -> bool:
"""Tests timeout cancellation behavior using move_on_after."""
return anyio.run(_timeout_checker, delay, timeout_limit)
async def _event_coordination() -> Tuple[bool, bool]:
event = anyio.Event()
before_flag = False
after_flag = False
async def waiter() -> None:
nonlocal before_flag, after_flag
before_flag = event.is_set()
await event.wait()
after_flag = event.is_set()
async with anyio.create_task_group() as tg:
tg.start_soon(waiter)
await anyio.sleep(0.005)
event.set()
return before_flag, after_flag
def coordinate_with_event() -> Tuple[bool, bool]:
"""Demonstrates task synchronization using anyio.Event."""
return anyio.run(_event_coordination)
def _cpu_bound_task(a: int, b: int) -> int:
time.sleep(0.005)
return a + b
async def _thread_offload(a: int, b: int) -> int:
return await anyio.to_thread.run_sync(_cpu_bound_task, a, b)
def execute_in_worker_thread(a: int, b: int) -> int:
"""Demonstrates offloading blocking sync execution using to_thread.run_sync."""
return anyio.run(_thread_offload, a, b)
"""Contract verification test for pkg:pypi/anyio@4.13.0."""
import sys
from pathlib import Path
# Ensure src is in python path
src_dir = Path(__file__).resolve().parent.parent / "src"
if str(src_dir) not in sys.path:
sys.path.insert(0, str(src_dir))
from sample import (
run_entrypoint,
run_task_group_tasks,
stream_pipeline,
check_timeout_cancellation,
coordinate_with_event,
execute_in_worker_thread,
)
def test_contract_1_run():
# Assertion: anyio.run executes an async entrypoint coroutine and returns its result
result = run_entrypoint(7, 6)
assert result == 42, f"Expected 42, got {result}"
def test_contract_2_task_group():
# Assertion: create_task_group coordinates concurrent tasks and manages their lifecycle
inputs = [3, 1, 4, 2]
results = run_task_group_tasks(inputs)
assert results == [10, 20, 30, 40], f"Expected [10, 20, 30, 40], got {results}"
def test_contract_3_memory_stream():
# Assertion: create_memory_object_stream provides typed asynchronous item streaming between tasks
data = ["packet-a", "packet-b", "packet-c"]
received = stream_pipeline(data)
assert received == data, f"Expected {data}, got {received}"
def test_contract_4_move_on_after():
# Assertion: move_on_after cancels execution when the allotted timeout duration expires
was_cancelled = check_timeout_cancellation(delay=0.1, timeout_limit=0.01)
assert was_cancelled is True, f"Expected timeout cancellation True, got {was_cancelled}"
not_cancelled = check_timeout_cancellation(delay=0.001, timeout_limit=0.1)
assert not_cancelled is False, f"Expected cancellation False, got {not_cancelled}"
def test_contract_5_event():
# Assertion: Event facilitates asynchronous signaling and task coordination
before_set, after_set = coordinate_with_event()
assert before_set is False, "Event should not be set before signal"
assert after_set is True, "Event should be set after signal"
def test_contract_6_to_thread():
# Assertion: to_thread.run_sync offloads blocking synchronous execution to worker threads
sum_val = execute_in_worker_thread(123, 456)
assert sum_val == 579, f"Expected 579, got {sum_val}"
def main():
print("Running contracts for pkg:pypi/anyio@4.13.0...")
test_contract_1_run()
test_contract_2_task_group()
test_contract_3_memory_stream()
test_contract_4_move_on_after()
test_contract_5_event()
test_contract_6_to_thread()
print("All contracts passed successfully.")
if __name__ == "__main__":
main()
Seeder d'origine
anonyme