Comments (2)
Thanks for the bug report @kor0p. It would definitely be helpful to improve the situation here. With handlers, the main question is whether the callee of the handler will want a sync context or an async one. I don't think there is any reasonable way to introspect this. It would be a good idea to add support for something like this in add_event_listener
.
There are also more significant issues about the interaction between stack switching and and async contexts which will have to be ironed out. In particular, our event loop should ideally enter execution contexts with stack switching enabled if the runtime supports it. Since our event loop is calling into the function, we know the context is async. Though this could potentially lead to funny things like this not working:
def handler(event):
function_that_uses_syncify()
print('Hi here')
addListener(handler)
but being fixed if we make it into async def handler
.
For now a possible workaround is:
from pyodide.ffi import create_proxy
import asyncio
import js
async def async_handler():
await asyncio.sleep(0.1)
print('Hi there')
def handler(event):
asyncio.create_task(async_handler()).syncify()
print('Hi here')
handler_px = create_proxy(handler)
f = handler_px.callSyncifying.bind(handler_px)
js.document.body.addEventListener('click', f)
from pyodide.
but being fixed if we make it into
async def handler
.
Great! I'll try it)
For now a possible workaround is:
from pyodide.ffi import create_proxy import asyncio import js async def async_handler(): await asyncio.sleep(0.1) print('Hi there') def handler(event): asyncio.create_task(async_handler()).syncify() print('Hi here') handler_px = create_proxy(handler) f = handler_px.callSyncifying.bind(handler_px) js.document.body.addEventListener('click', f)
Thanks! That also can help me)
But using async handlers as default looks like better choice ð
(Off topic, just my emotions ð)
I'm very excited to be (for now just a little) part of Pyodide
It sounds crazy ðĪŠ, but I'm creating frontend framework based on Pyodide. Maybe I'm Pythonic to the core, but I believe that everything should be written in Python ð
So, if there is Python in browser, there should be Python frontend framework ð
Thanks you all for your work here
from pyodide.
Related Issues (20)
- mapbox-earcut
- Add option to prevent default type translations HOT 4
- Allow overriding compile parameters in pywasmcross HOT 1
- Debug pyodide release artifacts (and pyodide build debug support)
- "Building and testing Python packages out of tree" commands need some dev tools installed as prerequisites HOT 4
- Add esbuild-py HOT 4
- Add `PyMuPDF` package
- runPython return missing
- cmake -E capabilities is broken HOT 1
- Release 0.26.0 HOT 5
- datasets (huggingface) HOT 6
- Cannot create a WebGL2 context when using SDL HOT 3
- request to add pandasai HOT 1
- request to add llama-index
- request to add langchain HOT 1
- request to add Boto3 HOT 4
- fastobo
- loadPackage() not to access the file system if the cache already exists HOT 2
- cvxpy-base 1.4.3 HOT 2
- html5_canvas_backend no longer works. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
ð Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ððð
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google âĪïļ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyodide.