Skip to content

Fallbacks for threading-less environment? #1268

Description

@ryanking13

Things to check first

  • I have searched the existing issues and didn't find my feature already requested there

Feature description

I wonder if it would make sense for AnyIO functions that use threading in the background gets fallback to the single-threaded version when threading is not available.

For example, anyio.open_file currently uses aynio.to_thread.run_sync internally, and using it in threading-less environment such as WebAssembly fails with can't start new thread error.

Use case

I maintain Pyodide + WebAssembly/Emscripten platform in CPython. In WebAssembly environment, often threading is not available and codes that use threading runs into a runtime error.

Users of startlette and FastAPI were having issues porting their application to WebAssembly, as codes such as anyio.open_file or anyio.to_thread.run_sync requires threading support in the runtime environment.

Originally, I was discussing this issue in starlette (Kludex/starlette#3284), but I was wondering if this can be solved in AnyIO side, by providing threading-less fallbacks of those functions.

Of course, I understand that running everything including the I/O functions in the same thread means it will degrade the performance. But it would help users port their existing codes that use AnyIO without modification.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions