Restarting an app that uses Trio async functions

43 views
Skip to first unread message

Mauricio Vidal

unread,
Jul 8, 2022, 2:26:12 PM7/8/22
to Kivy users support
Hi all:

My app modifies the config.ini when the touch calibration is performed by the user which, of course,  is done after the current config.ini has been loaded.

According to Kivy's doc https://kivy.org/doc/stable/api-kivy.config.html I need to restart the app to apply the changes on the config file. I'm not aware of other alternatives to achieve the reload.

But I'm aware the app can be restarted calling a custom method like the following pseudo code:

class FrontendHMI(App):
    ...
    def restart(self):
           """
           Restarts this App.
           """
           self.root.clear_widgets()
           self.stop()
           return FrontendHMI().run()

However in my case, I'm using that with a app that implements Trio to use async routines based on this example: https://github.com/kivy/kivy/blob/master/examples/async/trio_advanced.py

While the self.stop() correctly stops all the async functions, the last line FrontendHMI().run() is not correct (It leads to Kivy be trapped in a loop with no other async functions and complaining about the already defined classes).

I guess I should be looking for a way to call the `app_func` method introduced in the example as this is the one in charge of scheduling the async functions.

But if I try to invoque:

    trio.run(AsyncApp().app_func)

Instead the last line of the above `restart`, I get this:

RuntimeError: Attempted to call run() from inside a run()

I'm quite lost here. May I have any clues about what is the correct way do deal with this?

Thank you!

Elliot Garbus

unread,
Jul 8, 2022, 3:12:01 PM7/8/22
to kivy-...@googlegroups.com

Sounds like you want to use os.exec from the os module.  See: https://docs.python.org/3/library/os.html#os.execlp

 

I don’t know if this will work on Android.

 

Here I a link that shows an example: https://groups.google.com/g/kivy-users/c/m5bh8dXU60s/m/LQfP4l6dCAAJ

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/33f505ba-3f9a-4c14-a787-ad0609254c94n%40googlegroups.com.

 

Mauricio Vidal

unread,
Jul 8, 2022, 5:16:05 PM7/8/22
to Kivy users support
Thank you Elliot for your help!

That was the fast solution. Now, my new `restart` method goes like this for the App object:

    def restart(self):
        self.stop()
        os.execvp(sys.executable, ['python'] + sys.argv)

Which works on both my deployment Linux and development macOS having also the virtue of preserving the Process ID and also, the environment of the current process.

Thank you again!
Reply all
Reply to author
Forward
0 new messages