This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Can plasmoids/plasma applets use threads or not

Tags: None
(comma "," separated)
User avatar
silvermoon
Registered Member
Posts
41
Karma
0
I just started making a few plasmoids for myself. Could make most things work, except that it seems impossible to create a thread in applets.
Check the basic example below.

I tried creating threads using thread, threading, QThread
But all would crash the applet and python would say

Code: Select all
Fatal Python error: This thread state must be current when releasing
Fatal Python error: PyEval_AcquireThread: non-NULL old thread state
Unable to start Dr. Konqi


So is it impossible to create a thread in plasmoids ?

this program crashes 8/10 and works 2/10 times.
Code: Select all
# -*- coding: utf-8 -*-
# <Copyright and license information goes here.>
from PyQt4.QtCore import Qt
from PyKDE4.plasma import Plasma
from PyKDE4 import plasmascript

import thread

class HelloPython(plasmascript.Applet):
   def __init__(self,parent,args=None):
      plasmascript.Applet.__init__(self,parent)

   def init(self):
      self.setHasConfigurationInterface(False)
      self.resize(125, 125)
      self.setAspectRatioMode(Plasma.Square)
      
#comment this and it wont crash
      thread.start_new_thread( abc, () )

   def paintInterface(self, painter, option, rect):
      painter.save()
      painter.setPen(Qt.white)
      painter.drawText(rect, Qt.AlignVCenter | Qt.AlignHCenter, "Hello Python!")
      painter.restore()

def abc():
   return None
      
def CreateApplet(parent):
    return HelloPython(parent)


another example using qthread

Code: Select all
# -*- coding: utf-8 -*-
# <Copyright and license information goes here.>
from PyQt4.QtCore import Qt, QThread
from PyKDE4.plasma import Plasma
from PyKDE4 import plasmascript

class Thread(QThread):
    def run(self):
        print 'hello from thread'

class HelloPython(plasmascript.Applet):
   def __init__(self,parent,args=None):
      plasmascript.Applet.__init__(self,parent)

   def init(self):
      self.setHasConfigurationInterface(False)
      self.resize(125, 125)
      self.setAspectRatioMode(Plasma.Square)
      
      self.t = Thread()
                self.t.start()

   def paintInterface(self, painter, option, rect):
      painter.save()
      painter.setPen(Qt.white)
      painter.drawText(rect, Qt.AlignVCenter | Qt.AlignHCenter, "Hello Python!")
      painter.restore()

def abc():
   return None
      
def CreateApplet(parent):
    return HelloPython(parent)


the above program crashes 1/10 and works 9/10

and when it crashes, it says
Code: Select all
hello from thread
Fatal Python error: This thread state must be current when releasing
KCrash: Application 'plasmoidviewer' crashing...
KCrash: Attempting to start /usr/lib/kde4/libexec/drkonqi from kdeinit
sock_file=/home/enlightened/.kde/socket-enlightened-desktop/kdeinit4__0
plasmoidviewer: Fatal IO error: client killed


is that a problem with the code, or the plasma ?

Regards
Silver Moon


KUBUNTU 18.04
User avatar
altagir
Registered Member
Posts
3
Karma
0
OS
Unsure within using Python, but developed a C++ plasma widget and been using QThread without issue in C++

Threading works well and was anyway required for me for UI performing long tasks (if not using service), else all of plasma engine would get stuck (like menu) if one plasma would sleep/wait on a task..
User avatar
silvermoon
Registered Member
Posts
41
Karma
0
Reported a bug here

https://bugs.kde.org/show_bug.cgi?id=320288

Anybody any idea ?


KUBUNTU 18.04
User avatar
einar
Administrator
Posts
3402
Karma
7
OS
It looks like an error in the Python code, either in the code itself, or in the binding. The crash is unrelated, because it's "simply" the deletion of a C++ object done by the Python GC when the error occurs.


"Violence is the last refuge of the incompetent."
Image
Plasma FAQ maintainer - Plasma programming with Python


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]