Closed martinRenou closed 6 months ago
blocking IO to work with emscripten. It's my understanding that it's impossible to perform blocking requests for byte ranges
I don't know how/if that would work. What would it look like in terms of code?
because this hangs the same event loop that JS uses
This is not correct, because the jupyterlite-xeus-python kernel runs in a web worker, so it does not hang the main thread thankfully. So you can make e.g. blocking XMLHttpRequest without freezing the page.
Ah yes, I forgot that the kernel acts in its own worker. That should help immensely. Now just to figure out CORS ;)
import pyjs
def request(method, url, body=None, headers={}):
assert body is None
js_request = pyjs.new(pyjs.js.XMLHttpRequest)
js_request.open(method, url, False)
for key, value in headers.items():
js_request.setRequestHeader(key, pyjs.to_js(value))
js_request.responseType = "arraybuffer"
js_request.send(pyjs.to_js(None))
response = pyjs.to_py(js_request.response)
return memoryview(response)
this is all not needed anymore, the request library should just work
@martinRenou I had another question that not relevant for this repo, but I can't think where to open an issue:
I want to adapt a library that performs blocking IO to work with emscripten. It's my understanding that it's impossible to perform blocking requests for byte ranges, because this hangs the same event loop that JS uses. Is that correct?
Originally posted by @agoose77 in https://github.com/emscripten-forge/recipes/issues/636#issuecomment-1716253974