Skip to content

Adapter#28

Open
MikiEEE wants to merge 4 commits into
developfrom
adapter
Open

Adapter#28
MikiEEE wants to merge 4 commits into
developfrom
adapter

Conversation

@MikiEEE

@MikiEEE MikiEEE commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Summary

This PR adds dependency-free execution adapters that let SmallOS tasks cooperate with libraries using blocking or asyncio-based runtime models.

  • Adds ThreadAdapter for blocking callables and synchronous database drivers.
  • Adds AsyncioAdapter backed by one persistent asyncio loop thread.
  • Introduces a shared adapter_call scheduler path for future adapter types.
  • Uses readiness-based completion notifications instead of scheduler polling.
  • Preserves user-library exception types at the await adapter.call(...) boundary.
  • Supports bounded capacity, cancellation, deterministic shutdown, and adapter diagnostics.
  • Keeps database connections, transactions, pooling, retries, and library dependencies in user code.
  • Adds modern generic typing so adapter results retain their callable return types.
  • Keeps desktop adapter imports out of core and MicroPython-oriented import paths.
  • Adds no runtime dependencies.

Examples

Standard-library-only examples demonstrate:

  • Blocking callable execution alongside ordinary SmallOS tasks.
  • A thread-affine sqlite3 connection using ThreadAdapter(max_workers=1).
  • Persistent asyncio queues, futures, and background tasks using AsyncioAdapter.

Safety and lifecycle

  • Adapters bind to one SmallOS runtime.
  • max_pending rejects excess work without blocking the scheduler.
  • Running Python threads cannot be forcibly cancelled.
  • Asyncio cancellation is requested on the adapter loop but may be delayed by foreign code.
  • Malformed adapter completions are rejected with AdapterProtocolError.
  • Unexpected asyncio loop or teardown failures are exposed through shutdown_error.

Validation

  • All 94 unit tests pass.
  • Branch coverage passes at 65%.
  • Pyright reports 0 errors and 0 warnings.
  • All three adapter demos pass.
  • Package, test, and demo compilation passes.
  • Wheel and source distributions build successfully.
  • Built artifacts include the adapters, examples, and typing contract.
  • Package metadata retains zero base runtime dependencies.

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.

1 participant