Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#2226 defect closed fixed (fixed)

qt4reactor.stop() not closing connections and quitting python

Reported by: Tantalum Owned by:
Priority: lowest Milestone:
Component: core Keywords: qt, qt4, qt4reactor
Cc: Branch:
Author:

Description

from PyQt4 import QtGui, QtCore
import qt4reactor                     
app = QtGui.QApplication(sys.argv) 
qt4reactor.install(app)

__Code for QtClientGui goes here. It's just a subclass of QMainWindow and a couple of widgets__

from twisted.internet import reactor
   def quit():
       print "Quiting app"
       app.quit()
       print "Stopping Reactor"
       reactor.stop()
       print "Reactor stopped"
       sys.exit()
       
   #Quit the app when the reactor stops
   reactor.addSystemEventTrigger('after', 'shutdown', app.quit)
   #Stop the reactor when the app quits
   QtCore.QObject.connect(app, QtCore.SIGNAL("lastWindowClosed()"), quit)
   #Create factory here and connect to the server
   reactor.connectTCP("My-Servers_Host", 5555, ManagerClient.ClientFactory(QtClientGui))
   reactor.run()

When the main window is closed "Reactor stopped" is printed but python keep on running. Also the connections to the client are not closed. The machiene is a Mac OS X PPC 10.4.6 running python 2.4.4 and Qt 4.1.0

Change History (5)

comment:1 Changed 11 years ago by therve

Owner: itamarst deleted
Priority: normallowest

qt4reactor is not even in the distribution, and probably never will. Patches in #1770 are welcome though.

comment:2 Changed 11 years ago by Tantalum

Resolution: fixed
Status: newclosed

To Fix this use t.i.p.ClientCreator().connectTCP() instead of reactor.connectTCP(). This also eleminates the need for a client factory.

comment:3 Changed 11 years ago by blais

I had this problem and the proposed fix did not work for me.

With some debugging I found that the cleanup() method was not getting called. I circumvented the problem by calling simulate() manually on stop(). Patch below:

Index: qt4reactor.py =================================================================== --- qt4reactor.py (revision 36846) +++ qt4reactor.py (working copy) @@ -177,7 +177,14 @@

self._crashCall = None

self.running = 0

+ def stop(self): + """Kludge to run simulate manually to avoid system events to fire. + (FIXME We're circumventing some sort of bug.) + """ + super(QTReactor, self).stop() + self.simulate() # Make sure we call the shutdown system events. +

def install(app=None):

"""Configure the twisted mainloop to be run inside the qt mainloop. """

comment:4 Changed 11 years ago by blais

buggerdibugbug I forget the wiki formatting, here goes again::

Index: qt4reactor.py
===================================================================
--- qt4reactor.py       (revision 36846)
+++ qt4reactor.py       (working copy)
@@ -177,7 +177,14 @@
             self._crashCall = None
         self.running = 0
 
+    def stop(self):
+        """Kludge to run simulate manually to avoid system events to fire.
+        (FIXME We're circumventing some sort of bug.)
+        """
+        super(QTReactor, self).stop()
+        self.simulate() # Make sure we call the shutdown system events.
 
+
 def install(app=None):
     """Configure the twisted mainloop to be run inside the qt mainloop.
     """



comment:5 Changed 7 years ago by <automation>

Note: See TracTickets for help on using tickets.