Bug 320288

Summary: Using threads in widgets, crashes them intermittently
Product: [Unmaintained] plasma4 Reporter: Silver Moon <m00n.silv3r>
Component: scriptenginesAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED UNMAINTAINED    
Severity: crash Keywords: testcase
Priority: NOR    
Version: 4.9.5   
Target Milestone: ---   
Platform: Other   
OS: Linux   
URL: http://pastebin.com/cNk0MG7w
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Source code of plasmoid, its small and simple

Description Silver Moon 2013-05-26 06:35:56 UTC
Small and simple widget : http://pastebin.com/cNk0MG7w

Run it using plasmoidviewer and it will crash 50% time and run 50% time.

WHY ?

Reproducible: Sometimes

Steps to Reproduce:
1. Create a new widget
2. Paste the code in it, http://pastebin.com/cNk0MG7w
3. Run it using plasmoidviewer
4. Close and run again, and keep doing that.
Actual Results:  
It crashes 50% of the time and runs 50% of the time

Expected Results:  
The plasmoid should work fine always ?

SOURCE
============

# -*- coding: utf-8 -*-

import threading, thread, time

# KDE and QT libraries
from PyQt4 import QtCore
from PyQt4.QtCore import *
from PyQt4.QtGui import QGraphicsLinearLayout
from PyKDE4.plasma import Plasma
from PyKDE4 import plasmascript

# Main applet class to create and launch the plasmoid
class analytics_applet(plasmascript.Applet):
	
	#constructor
	def __init__(self, parent, args=None):
		plasmascript.Applet.__init__(self, parent)
		
	# the init function is called when creating the applet
	def init(self):
		#self.setHasConfigurationInterface(False)
		self.setAspectRatioMode(Plasma.Square)

		self.theme = Plasma.Svg(self)
		self.theme.setImagePath("widgets/background")

		self.layout = QGraphicsLinearLayout(Qt.Vertical, self.applet)
		
		self.applet.setLayout(self.layout)
		self.resize(300,150)
		
		# START the worker thread
		self.thread = worker_thread()
		self.thread.start()

class worker_thread(QtCore.QThread):
	
	def __init__(self):
		QtCore.QThread.__init__(self)
		
	def run(self):
		
		while True :
			print 'OK'
			time.sleep( 1 )
		return

# this function is called by the plasma system to create and load the applet
def CreateApplet(parent):
	return analytics_applet(parent)








CRASH TRACE
============
Application: Plasma Widget Viewer (plasmoidviewer), signal: Aborted
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Current thread is 1 (Thread 0x7f2c4d0a1780 (LWP 10327))]

Thread 3 (Thread 0x7f2c33018700 (LWP 10328)):
#0  0x00007f2c4a784313 in poll () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007f2c43ab1d84 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#2  0x00007f2c43ab1ea4 in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#3  0x00007f2c4af04c16 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#4  0x00007f2c4aed52bf in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#5  0x00007f2c4aed5548 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#6  0x00007f2c4add6b10 in QThread::exec() () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#7  0x00007f2c4aeb59af in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#8  0x00007f2c4add9aec in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#9  0x00007f2c43f80e9a in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
#10 0x00007f2c4a78fccd in clone () from /lib/x86_64-linux-gnu/libc.so.6
#11 0x0000000000000000 in ?? ()

Thread 2 (Thread 0x7f2c2a207700 (LWP 10329)):
#0  0x00007f2c4a789033 in select () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007f2c31b5ed3d in ?? () from /usr/lib/libpython2.7.so.1.0
#2  0x00007f2c31b34d72 in PyEval_EvalFrameEx () from /usr/lib/libpython2.7.so.1.0
#3  0x00007f2c31b35c38 in PyEval_EvalCodeEx () from /usr/lib/libpython2.7.so.1.0
#4  0x00007f2c31b8bc76 in ?? () from /usr/lib/libpython2.7.so.1.0
#5  0x00007f2c31c051be in PyObject_Call () from /usr/lib/libpython2.7.so.1.0
#6  0x00007f2c31c694e0 in ?? () from /usr/lib/libpython2.7.so.1.0
#7  0x00007f2c31c051be in PyObject_Call () from /usr/lib/libpython2.7.so.1.0
#8  0x00007f2c31c05ac7 in PyEval_CallObjectWithKeywords () from /usr/lib/libpython2.7.so.1.0
#9  0x00007f2c3125c692 in ?? () from /usr/lib/python2.7/dist-packages/sip.so
#10 0x00007f2c315030f7 in ?? () from /usr/lib/python2.7/dist-packages/PyQt4/QtCore.so
#11 0x00007f2c31544050 in ?? () from /usr/lib/python2.7/dist-packages/PyQt4/QtCore.so
#12 0x00007f2c4add9aec in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#13 0x00007f2c43f80e9a in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
#14 0x00007f2c4a78fccd in clone () from /lib/x86_64-linux-gnu/libc.so.6
#15 0x0000000000000000 in ?? ()

Thread 1 (Thread 0x7f2c4d0a1780 (LWP 10327)):
[KCrash Handler]
#5  0x00007f2c4a6d2425 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#6  0x00007f2c4a6d5b8b in abort () from /lib/x86_64-linux-gnu/libc.so.6
#7  0x00007f2c31bc3f0e in Py_FatalError () from /usr/lib/libpython2.7.so.1.0
#8  0x00007f2c31c55b4b in PyGILState_Release () from /usr/lib/libpython2.7.so.1.0
#9  0x00007f2c3051ba93 in sipPlasma_AppletScript::constraintsEvent(QFlags<Plasma::Constraint>) () from /usr/lib/python2.7/dist-packages/PyKDE4/plasma.so
#10 0x00007f2c4c46c538 in Plasma::Applet::constraintsEvent(QFlags<Plasma::Constraint>) () from /usr/lib/libplasma.so.3
#11 0x00007f2c4c47d0c0 in ?? () from /usr/lib/libplasma.so.3
#12 0x00007f2c4c48cd6a in Plasma::Containment::addApplet(Plasma::Applet*, QPointF const&, bool) () from /usr/lib/libplasma.so.3
#13 0x000000000040a5ee in _start ()
Comment 1 Silver Moon 2013-05-26 06:37:28 UTC
Created attachment 80086 [details]
Source code of plasmoid, its small and simple

This is the source code of the plasmoid
Comment 2 Martin Flöser 2013-06-06 10:47:19 UTC
the crash trace is missing debug symbols for plasma, so it's not possible to see where it crashes.

Anyway from what we can see it crashes in Python, so it seems like this part is not thread safe.
Comment 3 Andrew Crouthamel 2018-09-04 19:15:57 UTC
Hello! Plasma 4 was replaced by Plasma 5 four years ago by the KDE community. In that time we have made great strides in stability and functionality. We are closing all Plasma 4 bugs as most of them are no longer applicable to the new frameworks Plasma 5 is built upon. If you could, please re-test with the latest version of Plasma 5, and submit a new bug to "plasmashell" if you continue to have an issue. Thank you!