Fix for KDE Plasma crashes

Sometimes, KDE’s plasmashell process closes for no reason.
that results in:

  • all panels disappear
  • all widgets close
  • desktop wallpaper go black
  • yakuake (drop-down terminnal) closes

and that is really annoying!


I don’t know why this happens.
it seems to be a bug.
I will leave it for the Manjaro and KDE developers to fix.
meanwhile, I have made a Python3 script to watch the “plasmashell” process. and when plasmashell closes due to that bug, the python script will re-launch it (and the yakuake terminal).


so if you face that problem:_

  1. install python3 psutil module: $ python3 -m pip install psutil
  2. copy this python script and save it in home dir as: relaunch_plasmashell.py
#!/usr/bin/python3
#import libs
import psutil, signal, os
import subprocess as sp
global relaunch_plasmashell; relaunch_plasmashell = True
def check_if_process_exists(name):
    for pid in psutil.pids():
        try: p = psutil.Process(pid)
        except: continue
        if p.name()==name: return True
    return False

def _quit(*args, **kwargs):
    global relaunch_plasmashell; relaunch_plasmashell = False
    print('||             Quitting...             ||')
    os._exit(0)

def main():
    #quit this script on reboot/shutdown/logout so that it wont re-launch plasmashell by mistake
    for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
        signal.getsignal(sig)
        signal.signal(sig, _quit)
    #check if plasmashell process exist
    #if yes: wait for it to close
    #if no: go to next step
    for pid in psutil.pids():
        try: p = psutil.Process(pid)
        except: continue
        if p.name()=='plasmashell':
            print('Found existing plasmashell & pid is:', p.pid)
            print('Waiting...')
            try: p.wait()
            except: _quit()
            break
    #if it already does not exist || when it closes: loop in re-opening it
    try: #(try) is to quit directly on keyboard interrupt
        while True:
            #check if plasmashell closed due to that bug or not
            relaunch_plasmashell = False
            pnames = ['klauncher', 'start_kdeinit', 'dbus-daemon', 'kded5', 'appimagelauncherd', 'kglobalaccel5', 'bluetoothd', 'systemd', 'udisksd', 'cryptd', '(sd-pam)', 'org_kde_powerdevil', 'xembedsniproxy', 'power-profiles-daemon', 'kwin_x11']
            for pid in psutil.pids():
                try: p = psutil.Process(pid)
                except: continue
                _name = p.name()
                if _name in pnames:
                    pnames.remove(_name)
                    if pnames == []:
                        relaunch_plasmashell = True
                        break
            if relaunch_plasmashell:
                #Re-open yakuake if it has closed
                if not check_if_process_exists('yakuake'):
                    print('Re-opening yakuake...')
                    p = sp.Popen(['/usr/bin/yakuake'], stderr=sp.STDOUT, stdout=sp.DEVNULL)
                    print('pid is:', p.pid)
                print('Re-opening plasmashell...')
                p = sp.Popen(['/usr/bin/plasmashell'], stderr=sp.STDOUT, stdout=sp.DEVNULL)
                print('pid is:', p.pid)
                print('Waiting...')
                p.wait()
            else: _quit()
    except KeyboardInterrupt: _quit()

if __name__ == '__main__': main()
  1. then make the file executable: sudo chmod +x ~/relaunch_plasmashell.py
  2. then make a .desktop file in /home/(your_username)/.config/autostart to auto start the script on system startup:
  • go to /home/(your_username)/.config/autostart
  • make a plain text file and name it relaunch_plasmashell.desktop
  • copy and paste this text into it:
[Desktop Entry]
Comment[en_US]=
Comment=
Exec=python3 /home/(your_username)/relaunch_plasmashell.py
GenericName[en_US]=
GenericName=
Icon=kde-logo
MimeType=
Name[en_US]=relaunch_plasmashell
Name=relaunch_plasmashell
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=

Note: replace “(your_username)” in the .desktop file with your actual username

Edit:-

  • Note: this script is a temporary fix. It has some downsides:-
    – it consumes 6 MB of RAM.
    – it makes shutdown/logout/reboot late for about 3 seconds because when plasmashell closes in shutdown process, the script can’t know that so the script re-launches it by mistake (and due to that: the shutdown/logout/reboot will be late for about 3 to 5 seconds)

Edit:-

  • fixed the 2nd downside: now the script will NOT relaunch plasmashell by mistake on shutdown/logout/reboot.

Edit:-

  • fixed a bug in the script.
3 Likes

Thanks for the script i also get annoyed with theses plasma shell crashes . I cant even imagine what unstable branch users went through as they had bleeding edge kde .

I’m very sure it isnt something manjaro team can fix.So kindly file a bug report on
https://bugs.kde.org

and make sure to read this before reporting
https://community.kde.org/Get_Involved/Issue_Reporting

.Your bug reports will help kde team make plasma better . :slightly_smiling_face:

3 Likes

I can reply to that … Aside of few minor bugs that are already known upstream and on the way to be fixed, the system works with no issue, no hassle, no crashes.

2 Likes

7 posts were split to a new topic: Crashes with plasma 5.23.4 after viewing YouTube or search for something with krunner