G
G
gunya2011-08-07 23:21:08
Python
gunya, 2011-08-07 23:21:08

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

5 answer(s)
Y
yeputons, 2011-08-08
@gunya

Event-driven is good.
In general, threads will save you

C
coxx, 2011-08-08
@coxx

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.

L
lifelover, 2011-08-08
@lifelover

Streams are evil.

C
coxx, 2011-08-08
@coxx

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.

M
Mobyman, 2011-08-08
@Mobyman

If you are interested, I can throw off my version of the network fault-tolerant gallows on python, it is really amateurish, but it can help :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question