
Hi Joe, On 09/04/2022 11:56, Joe Marshall wrote:
Is anyone working on adding synchronous sockets support in pyodide yet? > If not, does anyone have opinions on how it should be done? I can see with support for shared memory across browsers now it would be easy enough to do it with that in JavaScript with a web worker and atomics.wait.
I think the latest discussion about this was in https://github.com/pyodide/pyodide/issues/1503 and Hood also did some work on it in https://github.com/hoodmane/synclink I agree that using a web worker seems that most direct approach.
The obvious alternative would be to make threading and synchronisation primitives work in python and do fetch calls in a thread. Has anyone built threaded pyodide yet?
Threading is obviously a heavier weight thing, but on the other hand I guess it would fix lots of problems in a way that a dedicated JavaScript solution wouldn't.
Yes, I think we could eventually get treading enabled default, as discussed in https://github.com/pyodide/pyodide/issues/237. But it's a more long term subject.
Any ideas how that would interact with JavaScript?
Good question. Currently, JS access from Python works in web-workers as we initialize a separate Pyodide instance there. If it is created via Emscripten pthreads https://emscripten.org/docs/porting/pthreads.html, I guess it wouldn't work without changes to the FFI code and doing some of that initialization manually. Also, I have no idea whether passing JS objects wrapped into JsProxy between threads is even something we want to attempt. Maybe not. cc @Hood. But anyway, someone would need to try to build Pyodide with threading enabled first and seeing what happens :) Roman