Kivy app made with pyinstaller does not exit on Windows

150 views
Skip to first unread message

Gunnison Gunnison

unread,
Mar 31, 2020, 1:47:53 PM3/31/20
to Kivy users support
Could be a pyinstaller problem...

I can close the GUI window, but the task (and process) are still running.
I can build via pyinstaller with and without console. 
With console the console remains after closing the app.
I close the app via the X in top right. 
The console logs show the app.run() exiting.
I have to kill the task or process in task manager. 

Here are the exit logs in the console after closing the Kivy app:

INFO:__main__:on_request_closed exited
[INFO   ] [WindowSDL   ] exiting mainloop and closing.
INFO:kivy:[WindowSDL   ] exiting mainloop and closing.
[INFO   ] [Base        ] Leaving application in progress...
INFO:kivy:[Base        ] Leaving application in progress...
INFO:__main__:run exited

Here is my start and exit code:


class MainEchoApp(App):
    def build(self):
        self.title = 'ECHO'
        self.icon = 'media/logoico.png'
          # Execute cleaning function when exiting app
        Window.bind(on_request_close=save_settings)
        return RootWidget() 

    
if __name__ == '__main__':
    app = MainEchoApp()
    app.run()
    
    log.info('run exited')
    sys.exit()
    log.info('sys exit') # never get here...


Thanks,

Brian
 

Robert Flatt

unread,
Mar 31, 2020, 1:57:51 PM3/31/20
to Kivy users support
Clearly the app is exiting, and 'in theory?' Python too.
Pyinstaller logs can be verbose, but I'd go through the pyinstaller log looking for any line I didn't understand.

Elliot Garbus

unread,
Mar 31, 2020, 1:59:30 PM3/31/20
to kivy-...@googlegroups.com

My suggestion: have app.run() be the last thing in your file.

Move the code you want to run at exit into on_stop()

 

In App

 

def on_stop(self):

    # code you want to run when the app closes.

--
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/2ca1facf-1755-4e6a-9a6f-f9b84d41dd00%40googlegroups.com.

 

Gunnison Gunnison

unread,
Mar 31, 2020, 3:45:04 PM3/31/20
to Kivy users support
OK,

Thanks.

on_stop does not fix this issue. But it does as advertised. 


class MainEchoApp(App):
    def build(self):
        self.title = 'ECHO'
        self.icon = 'media/logoico.png'
        return RootWidget() 

    def on_stop(self):
        log.info('on_stop')
        if gsettings is not None:
            gsettings.close()
        log.info('on_stop exited')


if __name__ == '__main__':
    app = MainEchoApp()
    app.run() 
    log.info('run exited')
   


[INFO   ] [WindowSDL   ] exiting mainloop and closing.
INFO:kivy:[WindowSDL   ] exiting mainloop and closing.
[INFO   ] [Base        ] Leaving application in progress...
INFO:kivy:[Base        ] Leaving application in progress...
INFO:__main__:on_stop
...
INFO:__main__:on_stop exited
INFO:__main__:run exited

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Mar 31, 2020, 4:10:42 PM3/31/20
to kivy-...@googlegroups.com
Is there something that could be keeping the thread open?
If you remove the code after run() do you still see this issue?  You are running a kivy component after the event loop has exited. 

Sent from my iPhone

On Mar 31, 2020, at 12:48 PM, Gunnison Gunnison <bgun...@gmail.com> wrote:


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/5f9ef487-be7e-4e80-9f7e-f6299fa1b52e%40googlegroups.com.

Gunnison Gunnison

unread,
Mar 31, 2020, 5:44:44 PM3/31/20
to Kivy users support
Thanks,

The logs are from Python logger not Kivy logging. 

I turned on debug=True in PyInstaller spec and see at end of console logs. 
I was thinking I left a "if __name__ == '__main__':" in my included Python modules, but no.
I'm thinking it is PyInstaller issue now. 

INFO:__main__:on_stop exited
INFO:__main__:run exited
[5532] LOADER: Running midi_echo.py
[5532] LOADER: Running midi_effect_manager.py
[5532] LOADER: Running midi.py
[5532] LOADER: Running upper_class_utils.py
[5532] LOADER: OK.
[5532] LOADER: Cleaning up Python interpreter.


Elliot Garbus

unread,
Mar 31, 2020, 6:01:14 PM3/31/20
to kivy-...@googlegroups.com

I’ve never had this issue with pyinstaller.  Is there some connection or file you could have left open that is causing the process not to clean up?

I see your doing midi, are you closing the ports? (just guessing)

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/010359c4-f616-426e-b3aa-ffb20528bae1%40googlegroups.com.

 

Gunnison Gunnison

unread,
Mar 31, 2020, 6:08:48 PM3/31/20
to Kivy users support


On Tuesday, March 31, 2020 at 3:01:14 PM UTC-7, Elliot Garbus wrote:

I’ve never had this issue with pyinstaller.  Is there some connection or file you could have left open that is causing the process not to clean up?

I see your doing midi, are you closing the ports? (just guessing)

 

 No ports are opened in this case, but good guess ;)

     Curious how PyInstaller finds which module to execute from. Must be one with "if __name__ == '__main__':"
     Or should I Specify it. Appreciate your help, I'm gonna blame PyInstaller for now...

 

Elliot Garbus

unread,
Mar 31, 2020, 7:07:01 PM3/31/20
to kivy-...@googlegroups.com

It is specified in the spec file.

Here is my spec file for Windows10:

 

# -*- mode: python -*-

import os
from kivy_deps import sdl2, glew

spec_root = os.path.abspath(SPECPATH)
block_cipher = None
app_name = 'Chase Bliss Editor'
win_icon = '../Images/cb_icon.ico'

a = Analysis(['../main.py'],
             pathex=[spec_root],
             datas=[('../*.kv', '.'), ('../Images/*.png', './Images')],
             hiddenimports=['win32timezone'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name=app_name,
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=False,
          console=False,
          icon=win_icon)
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
               strip=False,
               upx=False,
               name=app_name)

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/51f3f7c0-4df0-4843-8291-d3830cafe222%40googlegroups.com.

 

Gunnison Gunnison

unread,
Mar 31, 2020, 8:33:25 PM3/31/20
to Kivy users support
OK, appreciate the help. It was a thread hanging on for dear life. 
I found it by running in the IDE, closing the window, then pausing the program and it stopped in the thread. 
With a proper thread killer all is well. 

Thanks!
Reply all
Reply to author
Forward
0 new messages