"StackHash_0a9e error" when exit from python
Question: I'm a beginner of python,I wrote a small program, when I exit the program,
sometimes （more than 50% probability） it show an error.This occurred only
after I **exit** the program.Could you please help me to find is there
something wrong with my code.

Really thanks.

ps:I'm using python3.3 and pyqt4 on win7 sp1 x64

**error:**

    
    
     问题签名:
     问题事件名称:    BEX
     应用程序名: python.exe
     应用程序版本:    0.0.0.0
     应用程序时间戳:   5150c40a
     故障模块名称:    StackHash_0a9e
     故障模块版本:    0.0.0.0
     故障模块时间戳:   00000000
     异常偏移:  00388100
     异常代码:  c0000005
     异常数据:  00000008
     OS 版本: 6.1.7601.2.1.0.256.1
     区域设置 ID:   2052
     其他信息 1:    0a9e
     其他信息 2:    0a9e372d3b4ad19135b953a78882e789
     其他信息 3:    0a9e
     其他信息 4:    0a9e372d3b4ad19135b953a78882e789
    

**console return this:**

Process finished with exit code -1073741819

**main code:**

    
    
    import urllib
    import http.cookiejar
    import time
    import sys
    from bs4 import BeautifulSoup
    from PyQt4 import QtGui
    from PyQt4 import QtCore
    
    
    class BaiduMainWindow(QtGui.QMainWindow):
        def __init__(self, parent=None):
            super(BaiduMainWindow, self).__init__(parent)
            self.initUI()
    
        def initUI(self):
            self.centralwidget = BaiduWidget(self)
            self.setCentralWidget(self.centralwidget)
            self.resize(600, 400)
            self.move(QtGui.QApplication.desktop().screen().rect().center() - self.rect().center())
            self.statusBar().showMessage('Ready')
    
    
    class BaiduWidget(QtGui.QWidget):
        def __init__(self, parent):
            super(BaiduWidget, self).__init__(parent)
            self.initUI()
    
        def initUI(self):
            lb = QtGui.QLabel('Search Word')
            self.keyWordEdit = QtGui.QLineEdit()
            self.OKButton = QtGui.QPushButton('Search')
            self.containFilter = QtGui.QLineEdit()
            self.exceptFilter = QtGui.QLineEdit()
            self.result = QtGui.QTextBrowser()
    
            spacerItem = QtGui.QSpacerItem(30, 50)
    
            grid = QtGui.QGridLayout()
            grid.setSpacing(10)
            grid.addItem(spacerItem, 0, 0)
            grid.addWidget(lb, 1, 0)
            grid.addWidget(self.keyWordEdit, 2, 0)
            grid.addWidget(self.OKButton, 5, 0)
            grid.addItem(spacerItem, 7, 0)
            grid.addWidget(self.result, 0, 1, 8, 1)
            grid.setColumnStretch(1, 4)
            self.setLayout(grid)
    
    
    
    if __name__ == '__main__':
        app = QtGui.QApplication(sys.argv)
        form = BaiduMainWindow()
        form.show()
        sys.exit(app.exec_())
    


Answer: The problem is: `spacerItem` has beed added to `grid` twice. This object would
probably be freed twice by Qt when you exited the program.

    
    
        def initUI(self):
            lb = QtGui.QLabel('Search Word')
            self.keyWordEdit = QtGui.QLineEdit()
            self.OKButton = QtGui.QPushButton('Search')
            self.containFilter = QtGui.QLineEdit()
            self.exceptFilter = QtGui.QLineEdit()
            self.result = QtGui.QTextBrowser()
    
            spacerItem = QtGui.QSpacerItem(30, 50)
    
            grid = QtGui.QGridLayout()
            grid.setSpacing(10)
            grid.addItem(**spacerItem** , 0, 0)
            grid.addWidget(lb, 1, 0)
            grid.addWidget(self.keyWordEdit, 2, 0)
            grid.addWidget(self.OKButton, 5, 0)
            grid.addItem(**spacerItem** , 7, 0)
            grid.addWidget(self.result, 0, 1, 8, 1)
            grid.setColumnStretch(1, 4)
            self.setLayout(grid)
    
    

You should use two `QSpacerItem`s.

    
    
        def initUI(self):
            lb = QtGui.QLabel('Search Word')
            self.keyWordEdit = QtGui.QLineEdit()
            self.OKButton = QtGui.QPushButton('Search')
            self.containFilter = QtGui.QLineEdit()
            self.exceptFilter = QtGui.QLineEdit()
            self.result = QtGui.QTextBrowser()
    
            spacerItem = QtGui.QSpacerItem(30, 50)
            **spacerItem2 = QtGui.QSpacerItem(30, 50)**
    
            grid = QtGui.QGridLayout()
            grid.setSpacing(10)
            grid.addItem(spacerItem, 0, 0)
            grid.addWidget(lb, 1, 0)
            grid.addWidget(self.keyWordEdit, 2, 0)
            grid.addWidget(self.OKButton, 5, 0)
            grid.addItem(**spacerItem2** , 7, 0)
            grid.addWidget(self.result, 0, 1, 8, 1)
            grid.setColumnStretch(1, 4)
            self.setLayout(grid)
    
    

