Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PySide segmentation fault on QObject instantiation

I have a class that is a base for my other non-qt classes. This class instantiates QObject class with Signal instance. Unfortunately, sometimes it raises Segmentation Fault error. Here is my code:

class PublisherSignal(QObject):
    notify = Signal(list)


class PublisherBase:
    def __init__(self, *args, **kwargs):
        super(PublisherBase, self).__init__(*args, **kwargs)
        self._signal = PublisherSignal()

The faulthandler shows, that the segmentation fault is happening on the PublisherSignal() class instantiation. It is not always. In most cases it is working fine. No threads are involved. Subclasses of PublisherBase are not subclassing QObject.
What could be the cause of the segfaults?

like image 802
Djent Avatar asked Nov 16 '18 06:11

Djent


1 Answers

First: Segmentation fault is a complicated issue for developers. To effectively handle it use fault handler. It is a part of Python v.3.x but you could install it in Python v.2.x using pip. But sometimes you'd better use event filter Register – for a widget to track signal events for. Here's an example for mouse (it's just to see how it looks like):

# IT IS JUST AN EXAMPLE (NOT A SOLUTION)

def eventFilter(self, source, event):
    if event.type() == QEvent.MouseButtonPress:
        if source == self.txtEditor :
            pos=event.pos()
            cursor=self.txtEditor.cursorForPosition(pos)
            cursor.select(QTextCursor.WordUnderCursor)
            txtClicked=cursor.selectedText()
            self.testCommand(str(txtClicked))
    return QMainWindow.eventFilter(self, source, event)

Second: You might use The Python Debugger module:

python -m pdb yourScript.py

Third: For threads involved (but you said that no threads are involved).

shutdown (exit) can hang or segfault with daemon threads running
like image 155
mckade.charly Avatar answered Nov 20 '22 18:11

mckade.charly