Skip to content

docs(examples): fix broken and stale examples under examples/ - #694

Open
deanq wants to merge 5 commits into
mainfrom
deanq/sls-1000-fix-examples
Open

deanq wants to merge 5 commits into
mainfrom
deanq/sls-1000-fix-examples

Conversation

@deanq

@deanq deanq commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

What

Fixes the examples under examples/api, examples/endpoints, examples/serverless, and examples/rest_wrapper.py. examples/apps is unchanged: it matches the current SDK, and #557 already touches it.

File Problem Fix
endpoints/asyncio_job_request.py Unconditional asyncio.WindowsSelectorEventLoopPolicy() raises AttributeError on macOS and Linux. await job.output() with the default timeout raises TimeoutError immediately on current releases (SDK fix in #662). Remove the policy line. Pass an explicit timeout= to job.output().
api/create_endpoint.py runpod/base:0.4.4 does not exist on Docker Hub. Use runpod/mock-worker:latest, a real serverless worker.
api/create_template.py Very old runpod/base:0.1.0. runpod/base:2.0.0-ubuntu2404.
api/*, endpoints/* Comments point to runpod config, which no longer exists. Point to rp login.
endpoints/run_sync.py except TimeoutError misses requests.exceptions.Timeout, which is raised when the HTTP wait exceeds timeout. Catch both.
serverless/logger.py Documented output matched neither local nor deployed output. Document both: plain text locally, JSON when RUNPOD_ENDPOINT_ID is set.
serverless/concurrent_handler.py Handler named async_generator_handler was not a generator; the modifier was a no-op. A real async handler and a modifier that returns a set concurrency.
rest_wrapper.py Used stop_pod's response for the pod id. Keep the id from create_pod. Describe what the script does.
endpoints/health.py, run.py, run_sync.py, streaming.py Hardcoded endpoint ids. streaming.py sent mock-worker-only input without saying so. YOUR_ENDPOINT_ID placeholders; note which worker the streaming input targets.

Second commit: new-user pass

  • examples/README.md (new): prerequisites, which folder to start with, running handlers locally, getting an endpoint id, cost and cleanup. The top-level README's Examples link now points here instead of examples/apps.
  • api/*: unique names (re-running no longer collides on template names), cleanup commands, placeholder registry credentials. get_endpoints.py prints ids and names instead of every endpoint's full config, including env.
  • endpoints/run.py: waits with a timeout. The bare output() call printed None while the job was queued.
  • rest_wrapper.py: terminates the pod in finally, so a failed resume doesn't leave a billable pod running.

Why

None of these files run in CI, so they had drifted from the SDK. Running examples in CI is tracked separately.

Test plan

  • make quality-check (2773 passed)
  • serverless/logger.py: output matches the comments, both locally and with RUNPOD_ENDPOINT_ID set
  • serverless/concurrent_handler.py and simple_handler.py with --test_input
  • endpoints/asyncio_job_request.py, run.py, run_sync.py, health.py, streaming.py against a local fake API (RUNPOD_ENDPOINT_BASE_URL), with jobs going from IN_PROGRESS to COMPLETED
  • Docker Hub returns the image tags used
  • endpoints/run.py (second commit) against the fake API: prints the status, then the output
  • api/* and rest_wrapper.py not run: they create billable resources. Only the signatures and the image tags were checked.

deanq added 2 commits November 7, 2026 08:43
- asyncio_job_request: drop the Windows-only event loop policy that
  raised AttributeError on macOS and Linux; pass an explicit timeout
  to job.output()
- create_endpoint: replace a base image tag that does not exist with
  runpod/mock-worker:latest; refresh the create_template base image
- replace the removed `runpod config` command with `rp login`
- run_sync: also catch requests.exceptions.Timeout
- logger: document local text output and deployed JSON output
- concurrent_handler: use a real async handler and modifier
- rest_wrapper: keep the pod id from create_pod; describe what it does
- use YOUR_ENDPOINT_ID placeholders; note the mock-worker input

SLS-1000
- examples/README.md: prerequisites, which folder to start with,
  running handlers locally, getting an endpoint id, cost and cleanup
- point the top-level README Examples link at the index
- api examples: unique names, cleanup commands, placeholder
  registry credentials; get_endpoints prints ids and names only
  instead of every endpoint's env
- endpoints/run.py: wait with a timeout instead of printing None
- rest_wrapper.py: terminate the pod in a finally block

SLS-1000
@deanq deanq changed the title docs(examples): fix broken and stale examples (SLS-1000) docs(examples): fix broken and stale examples Nov 7, 2026
@celine-runpod celine-runpod changed the title docs(examples): fix broken and stale examples docs(examples): fix broken and stale examples (SLS-1000) Nov 9, 2026
@celine-runpod celine-runpod changed the title docs(examples): fix broken and stale examples (SLS-1000) docs(examples): fix broken and stale examples under examples/ (SLS-1000) Nov 9, 2026
@celine-runpod

Copy link
Copy Markdown
Contributor

bugbot run

@deanq deanq changed the title docs(examples): fix broken and stale examples under examples/ (SLS-1000) docs(examples): fix broken and stale examples under examples/ Nov 9, 2026
@deanq
deanq requested a balanced review from Copilot November 9, 2026 18:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified in the SDK examples and documentation updates.

No open issues 🎉

What changed in this PR

Updates the SDK’s examples to address stale usage, improve first-run guidance, and clarify resource costs and cleanup. The examples/apps examples remain unchanged.

Changes:

  • Adds an examples guide covering authentication, local testing, endpoint setup, and cleanup.
  • Fixes endpoint timeout handling and portability, updates worker images, and replaces hardcoded endpoint IDs.
  • Improves concurrency and logging examples, limits endpoint configuration output, and adds pod cleanup in finally.
File Description
README.md Points the Examples link to the new guide.
examples/​serverless/​logger.py Corrects documented local and deployed log output.
examples/​serverless/​concurrent_handler.py Demonstrates an async handler with fixed concurrency.
examples/​rest_wrapper.py Preserves the pod ID and terminates the pod in finally.
examples/​README.md Adds setup, usage, cost, and cleanup guidance.
examples/​endpoints/​streaming.py Uses an endpoint placeholder and documents mock-worker input.
examples/​endpoints/​run.py Waits for output with an explicit timeout.
examples/​endpoints/​run_sync.py Handles both job and HTTP request timeouts.
examples/​endpoints/​health.py Updates authentication guidance and the endpoint placeholder.
examples/​endpoints/​asyncio_job_request.py Removes the Windows-only policy and sets an output timeout.
examples/​api/​get_endpoints.py Prints endpoint IDs and names instead of full configurations.
examples/​api/​create_template.py Updates the image and generates unique template names.
examples/​api/​create_endpoint.py Uses a mock worker, unique names, and cleanup instructions.
examples/​api/​create_container_registry_auth.py Adds credential placeholders and cleanup guidance.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants