python - Using gobject.timeout_add_seconds - Segmentation Fault -


i writing gui program allows user repeatedly send message phone number configurable delay , number of repetitions.

i used qt designer create gui, , trying create code behind it. trying make program start sending messages when start button pressed, not freeze gui.

i trying use gobject.timeout_add_seconds check if new messages need send every 1s, when causing segmentation fault.

queuemessages called whenever button pressed start sending messages, , sendmessages should run every 1s send needed messages.

let me know if there easier way (such threading). open other ideas.

here's applicable code. can include gui code if helpful:

#!/usr/bin/python2.5 import sys, os import time import gobject pyqt4 import qtgui,qtcore smsbomb import *  class myform(qtgui.qmainwindow):     def __init__(self, parent=none):         #build parent user interface         qtgui.qwidget.__init__(self, parent)         self.ui = ui_mainwindow()         self.ui.setupui(self)         # create button actions         qtcore.qobject.connect(self.ui.btnsendmessages, qtcore.signal('clicked()'), self.queuemessages)         # check if need send messages every 1s.         self.maintimer = gobject.timeout_add_seconds(1, self.sendmessages)      def queuemessages(self):         # queue messages!         number = str(self.ui.txtnumber.text())         message = str(self.ui.txtmessage.text())         delay = int(self.ui.txtdelay.text())         repetitions = int(self.ui.txtrepetitions.text())         in range(repetitions):             os.system('dbus-send --dest=org.qgvdial.textserver --session --print-reply /org/qgvdial/textserver org.qgvdial.textserver.text array:string:"+1' + number + '" string:"' + message + '"')             #time.sleep(delay)      def sendmessages(self):         # send queued messages needed         print "sending queued messages..."         return true  if __name__ == "__main__":     app = qtgui.qapplication(sys.argv)     myapp = myform()     myapp.show()     sys.exit(app.exec_()) 

you appear using (py)gtk timer object within (py)qt application. try replacing

    self.maintimer = gobject.timeout_add_seconds(1, self.sendmessages) 

with equivalent pyqt code

    self.maintimer = qtcore.qtimer(self);     self.connect(self.maintimer, qtcore.signal('timeout()'), self.sendmessages)     self.maintimer.start(1000) 

i able reproduce segfault using gobject.timeout_add_seconds, , went away once replaced pygtk timer pyqt one. can't sure why happens, this article gives possible reason:

one caveat found, gobject.timeout_add_seconds() seems depend on gtk main loop, cannot use regular non-gtk python application.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -