Answer the question
In order to leave comments, you need to log in
Python - two main loops
Hello. I am learning python, writing a program, jabber client with gui.
The problem is:
In both programs, you need to process information in a loop, for XMPP you need something like
A in all wrappers for the GUI (Tkinter, PySide, I didn’t really look for it, in principle), you also need to do mainloop (Example for PySide):
So - the problem is that I need to do this at the same time, while only writing crutches comes to mind. Is there any possibility to implement such an application? If so, how? If some library has the ability to do this with basic tools, it would be wonderful. Tell me which way to dig.
client = xmpp.protocol.Client(...)
while true:
....client.Process()
# Create a Qt application
app = QApplication(sys.argv)
# Something...
# Enter Qt application main loop
app.exec_()
Answer the question
In order to leave comments, you need to log in
By the way, rather for general development, threads are not the only approach to developing a network client with a GUI. For example, there is the Telepathy framework . In it, the network client is, in fact, a daemon that interacts with the frontend via D-Bus.
A traditional GUI mainloop is essentially a regular "while true:" in which, among other things, the interface is redrawn and user input is processed. Therefore, in a single-threaded program, the GUI will hang on any blocking operations (calculations, I/O, or just time.sleep()).
If you want to learn not only python, but also Qt itself, then you should look at Qt threads.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question