Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronous Python & async JavaScript? #36

Open
cshaa opened this issue May 26, 2023 · 1 comment
Open

Synchronous Python & async JavaScript? #36

cshaa opened this issue May 26, 2023 · 1 comment
Labels
question Further information is requested

Comments

@cshaa
Copy link

cshaa commented May 26, 2023

In contrast to most JavaScript code, Python libraries often work synchronously and may even expect one's callback function to resolve synchronously, even if that doesn't make sense in JavaScript environment. One example might be the audible Python package that performs all HTTP requests synchronously and expects a synchronous callback to show an image to the user and get their response.

I have no experience with Deno's FFI yet, but it seems to me that calling synchronous Python functions asynchronously should be possible, as the Python interpreter runs in a different thread. Similarly, I would expect "converting" asynchronous JS functions to synchronous Python callbacks should be possible, if one blocks the Python interpreter until the JS promise is settled.

Is this something that sounds viable to you? And if so, is this something you'd be interested in adding to this library?

@cshaa cshaa changed the title Asynchronous callback? Synchronous Python & async JavaScript? May 26, 2023
@DjDeveloperr
Copy link
Member

While it should be possible to call sync Python functions asynchronously, the latter doesn't seem to work out. I tried it out and there is a deadlock. JS event loop does not step in an FFI callback's context which is further being waited upon by Python.

@eliassjogreen eliassjogreen added the question Further information is requested label Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants