extremeheat / JSPyBridge

🌉. Bridge to interoperate Node.js and Python
MIT License
694 stars 53 forks source link

Multiple await python calls throw exception #48

Open nicolo-faedi opened 2 years ago

nicolo-faedi commented 2 years ago

Hello! I'm actually using Pythonia as bridge to include some python libraries and functions inside my production js server which has a RestFull API for quering db data.

First i'm loading all the python modules i need, then i export all the async functions to distribute them over my application. When i call pythonia functions in a foreach loop, i got this behaviour i can't solve. (i've also tried with a sync loop, same result) Some data will be returned by python function and printed, then it stops.

The error: Schermata 2022-02-16 alle 14 01 59

Here my sample code:

In my Express api Schermata 2022-02-16 alle 13 59 40

My Pythonia API Schermata 2022-02-16 alle 13 59 27

Thanks for your attention

nicolo-faedi commented 2 years ago

Just tried to debug a little bit by my self, and I noted there's a {'r': 10072, 'action': 'value', 'ffid': 4, 'key': [], 'val': ''} fired from Javascript to Python, completely out of my control, which breaks the code.

extremeheat commented 2 years ago

Python main thread is likely getting blocked (since you're using forEach, you're not waiting for last computation), use await to make sure you wait for a response from the Python side before sending more calls.

for await (const value of db_data) {
  const python_res = await pythonia_api.func(value)
  // do something with python_res
}
extremeheat commented 2 years ago

Hello

Is this still an issue? Have you gotten this to work?