chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
807 stars 132 forks source link

receive real-time output from Python #1090

Closed iot-future closed 7 months ago

iot-future commented 7 months ago

Chaquopy version

Chaquopy :14

Issue Description:

I am using Chaquopy to embed Python in an Android application and would like to be able to receive real-time output from Python functions in my Java code.

Specific Details:

I have successfully called Python functions in my Java code and can see the output of these functions in logcat. However, I would like to be able to access this output in my Java code in real-time for further processing or display in the user interface.

Expected Solution:

I would like to retrieve the output of Python functions in my Java code, rather than just viewing it in logcat. I have explored some approaches, but haven't found a solution yet.

Additional Notes:

My development environment is Android Studio, and I'm using the 14th version of Chaquopy. If you need more information, please let me know.

Thank you for your assistance!

mhsmith commented 7 months ago

I can't answer in any detail without knowing more about what your code does. But your Python function can return any object it wants, and your Java code can then access it using the PyObject API. Or if your Python function takes a long time to return, you can run it on a background thread, pass it a Java object, and have it call methods on that object to provide updates to the UI.

iot-future commented 3 months ago

图片3 You can output the intermediate value you need to use to the system console through the print function, and then call the adb debugger to get the output of Python.stdout in real time, and then get the procedure variable during the running of python code.