Djent
Djent

Reputation: 3467

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?

Upvotes: 13

Views: 1101

Answers (1)

mckade.charly
mckade.charly

Reputation: 65

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

Upvotes: 4

Related Questions