[PyQt] two classes in same event loop
Steve Castellotti
sc at puzzlebox.info
Wed Jul 7 14:09:08 BST 2010
Hello all-
I have created two application classes using PyQt, one a server
which normally runs in console mode, the other a client with complete
GUI. The server opens a socket and listens for connections from the
client which issue various commands to be carried out. These are bother
working quite well.
I would like to produce a third script which launches bother the
server and client processes at the same time, with all communication
happening over localhost. The point is to allow the user to run the
"network" version of the interface (connecting to the separate server
process over the network) or a "local" version which is self-contained
(including the server), while reusing the same code as much as possible.
This last piece is nearly working, however the server component in
the third "local" script is timing out during the communication process.
I am wondering if I am simply failing to properly initialize the two
class instances in order to share the single event loop.
When launching the client application in "network" mode, the code looks
something like this:
app = QtGui.QApplication(sys.argv)
window = client_interface(log)
window.show()
sys.exit(app.exec_())
When launching the server application from the console for "network"
mode, the code looks like this:
# Perform KeyboardInterrupt handling
signal.signal(signal.SIGINT, signal.SIG_DFL)
app = QtCore.QCoreApplication(sys.argv)
server = network_server(log, server_interface, server_port)
sys.exit(app.exec_())
And when trying to launch both in the same event loop for the "local"
third script, I'm doing:
app = QtGui.QApplication(sys.argv)
server = server.network_server(log, server_interface, server_port)
window = client.client_interface(log)
window.show()
sys.exit(app.exec_())
In the server code, process control happens something like this:
...
self.socket.newConnection.connect(self.processConnection)
...
def processConnection(self):
clientConnection = self.socket.nextPendingConnection()
if not clientConnection.waitForReadyRead(5000):
print "Timeout waiting for client to transmit data"
...
etc.
Currently each time the client goes to send data to the server, the
connection seems to establish and the client side reports writing to the
socket, but the server side times out after five seconds without the
data packet having been received. The client GUI interacts properly, and
the server routines seem to be getting called properly.
The odd thing is I can start up the "local" integrated script, which
will launch the server process (opening and listening to the port) as
well as the client GUI, then connecting that server process by launching
an instances of the "network" mode client GUI (so now there's two GUIs
on the screen), and everything works fine with the second GUI. So it
would seem the server side of the "local" script is working just fine.
Can anyone offer me pointers regards what I might be doing wrong, or
perhaps where to look next?
Cheers
Steve Castellotti
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100707/ac134742/attachment.html>
More information about the PyQt
mailing list