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

run_in_executor not working on android #2479

Closed
cozimus opened this issue Apr 4, 2024 · 1 comment · Fixed by #2481
Closed

run_in_executor not working on android #2479

cozimus opened this issue Apr 4, 2024 · 1 comment · Fixed by #2481
Labels
android The issue relates to Android mobile support. enhancement New features, or improvements to existing features.

Comments

@cozimus
Copy link

cozimus commented Apr 4, 2024

Describe the bug

Refering to what reported here and here, the best approach to run a CPU-intensive task in backgroud is to use run_in_executor, that's works perfectly on Windows, but does not on Android.

Steps to reproduce

A minimum (not)-working example to reproduce the error is the following:

import toga, time

class MainApp(toga.App):
    def startup(self):

        self.main_window = toga.MainWindow(
            title=self.formal_name, size=(360, 654), resizable=True
        )
        self.label = toga.Label("")
        button = toga.Button("click here", on_press=self.click_handler)
        self.main_box = toga.Box(children=[button, self.label])
        self.main_window.content = self.main_box
        self.main_window.show()

        self.loop.create_task(self.loop_task())

    def click_handler(self, widget):
        self.label.text = "Clicked"

    async def loop_task(self):
        while True:
            await self.loop.run_in_executor(None, time.sleep, 1)
            self.label.text = time.time()


def main():
    return MainApp("Example App", "com.example")

Expected behavior

If your run it on Windows (via briefcase dev or briefcase run windows) it does the job update the label every second, but if I run it on android briefcase run android, the application freezes after the first render and don't respond

Screenshots

Environment

  • Operating System: Windows 11
  • Python version: 3.11.5
  • Software versions:
    • Briefcase: 0.3.17
    • Toga: 0.4.2
@cozimus cozimus added the bug A crash or error in behavior. label Apr 4, 2024
@cozimus cozimus changed the title run_in_executor in android not working run_in_executor not working on android Apr 4, 2024
@freakboy3742 freakboy3742 added enhancement New features, or improvements to existing features. android The issue relates to Android mobile support. and removed bug A crash or error in behavior. labels Apr 5, 2024
@freakboy3742
Copy link
Member

Thanks for the report. Right now, run_in_executor() isn't implemented on Android.

Interestingly, that code references the fact that "in the future", we may be able to restore run_in_executor(). Unless I'm missing something, it appears "the future" may be now. In my testing, restoring the default executor behavior implements the expected behavior. I've pushed #2481 to implement this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android The issue relates to Android mobile support. enhancement New features, or improvements to existing features.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants