Bug report #20424

crashed when use threading lib

Added by David Lopez almost 6 years ago. Updated almost 6 years ago.

Status:Closed
Priority:High
Assignee:-
Category:Python bindings / sipify
Affected QGIS version:3.4.1 Regression?:No
Operating System:Windows 7 Ultimate Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:Yes Copied to github as #:28244

Description

User Feedback

crashed when use threading lib

------- this is my class ---------

import threading
class ThreadingExample(object):
""" Threading example class
The run() method will be started and it will run in the background
until the application exits.
"""

def init(self, interval=1):
""" Constructor
:type interval: int
:param interval: Check interval, in seconds
"""
self.interval = interval
self.contador = 0
thread = threading.Thread(target=self.run, args=())
thread.daemon = True # Daemonize thread
thread.start() # Start the execution
def run(self):
""" Method that runs forever """
while True: # Do something
print('Doing something imporant in the background')
#print(self.interval)
time.sleep(self.interval)
def funcion(self, argumento):
while True:
self.contador += 1
print('hola ---------')

--------- crash when call ThreadingExample() ------------
I also use operations with geometries
this is the link that i use as ref:
http://sebastiandahlgren.se/2014/06/27/running-a-method-as-a-background-thread-in-python/

i tried to use QRunnable but also crash

class:
from PyQt5.QtCore import *

class Worker(QRunnable):
'''
Worker thread
'''
def init(self, fn, *args, **kwargs):
super(Worker, self).__init__() # Store constructor arguments (re-used for processing)
self.fn = fn
self.args = args
self.kwargs = kwargs

def run(self):
'''
Initialise the runner function with passed args, kwargs.
'''
self.fn(*self.args, **self.kwargs)

error comes when call:
def execute_this_fn(self):
print("Hello!")

def oh_no(self): # <-------- was connected to a button
    # Pass the function to execute
worker = Worker(self.execute_this_fn)
  1. Execute
    self.threadpool.start(worker) # <------ error

Report Details

Crash ID: 6f8bc6b84541925a551ee2a4507a028eb94a48e4

Stack Trace

QRasterPaintEngine::brushChanged :
QsciScintillaBase::inputMethodQuery :
QsciStyledText::text :
QsciStyledText::text :
QsciStyledText::text :
QsciStyledText::text :
QsciScintillaBase::inputMethodQuery :
PyInit_Qsci :
QWidget::event :
QFrame::event :
PyInit_Qsci :
QCoreApplicationPrivate::sendThroughObjectEventFilters :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QWidgetPrivate::drawWidget :
QApplication::windowIcon :
QWidget::event :
QgisApp::event :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QCoreApplicationPrivate::sendPostedEvents :
qt_plugin_query_metadata :
QEventDispatcherWin32::processEvents :
TranslateMessageEx :
TranslateMessage :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QDialog::exec :
PyMethodDef_RawFastCallKeywords :
PyMethodDef_RawFastCallKeywords :
PyEval_EvalFrameDefault :
PyFunction_FastCallDict :
PyMethodDef_RawFastCallDict :
PyObject_Call :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
QMetaObject::activate :
QAction::activate :
QAbstractButton::click :
QAbstractButton::mouseReleaseEvent :
QToolButton::mouseReleaseEvent :
QWidget::event :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QApplicationPrivate::sendMouseEvent :
QSizePolicy::QSizePolicy :
QSizePolicy::QSizePolicy :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QGuiApplicationPrivate::processMouseEvent :
QWindowSystemInterface::sendWindowSystemEvents :
QEventDispatcherWin32::processEvents :
TranslateMessageEx :
TranslateMessage :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QCoreApplication::exec :
main :
BaseThreadInitThunk :
RtlUserThreadStart :

QGIS Info
QGIS Version: 3.4.1-Madeira
QGIS code revision: 383851c597
Compiled against Qt: 5.11.2
Running against Qt: 5.11.2
Compiled against GDAL: 2.3.2
Running against GDAL: 2.3.2

System Info
CPU Type: x86_64
Kernel Type: winnt
Kernel Version: 6.1.7601

ejemplo.zip - estoy tratando de ejecutar procedimientos en segundo plano (54.6 KB) David Lopez, 2018-11-09 04:05 PM

History

#1 Updated by Giovanni Manghi almost 6 years ago

  • Crashes QGIS or corrupts data changed from No to Yes
  • Category changed from Python plugins to Python bindings / sipify
  • Priority changed from Normal to High

#2 Updated by luca bellani almost 6 years ago

I only insert my usb memory, and crash

Crash ID: 27a7a1737bab5acc1609b70f6389e7afee749d22

Stack Trace

QgsWinNative::initializeMainWindow :
QAbstractEventDispatcher::filterNativeEvent :
DispatchMessageW :
DispatchMessageW :
CharLowerBuffW :
KiUserCallbackDispatcher :
NtUserPeekMessage :
PeekMessageW :
PeekMessageW :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QCoreApplication::exec :
main :
BaseThreadInitThunk :
RtlUserThreadStart :

QGIS Info
QGIS Version: 3.4.1-Madeira
QGIS code revision: 383851c597
Compiled against Qt: 5.11.2
Running against Qt: 5.11.2
Compiled against GDAL: 2.3.2
Running against GDAL: 2.3.2

System Info
CPU Type: x86_64
Kernel Type: winnt
Kernel Version: 10.0.17763

#3 Updated by Nyall Dawson almost 6 years ago

  • Status changed from Open to Feedback

This is probably due to calling "print" from the background thread. You must never do gui based calls, like print, or accessing widgets, from background threads.

#4 Updated by David Lopez almost 6 years ago

you were right Nyall Dawson
thanks

i keep thinking that qgis should not crash

#5 Updated by Giovanni Manghi almost 6 years ago

  • Resolution set to invalid
  • Status changed from Feedback to Closed

Also available in: Atom PDF