agronholm / agronholm/anyio

Fallbacks for threading-less environment?

Aperta
#1,268 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
Python
Stelle
2.5k
Fork
260
Merge medio
1g 8h
PR unite (30g)
17

Descrizione

### Things to check first

- [x] 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](https://github.com/pyodide/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 (https://github.com/Kludex/starlette/pull/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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.