如何设计多线程GUI网络应用程序?

时间:2021-10-14 21:02:33

I'm working on a small utility application in Python.

我正在使用Python中的小型实用程序。

The networking is gonna send and receive messages. The GUI is gonna display the messages from the GUI and provide user input for entering messages to be sent. There's also a storage part as I call it, which is gonna get all the network messages and save them in some kind of database to provide some kind of search later.

网络将发送和接收消息。 GUI将显示来自GUI的消息,并提供用户输入以输入要发送的消息。我称之为存储部分,它将获取所有网络消息并将其保存在某种数据库中,以便稍后提供某种搜索。

What my question is, what would be the best way to design this? For sure all them have to happen in separate threads, but what I'm wondering is how to pass information between them the best way? What kind of signal passing / thread locking available in Python should I use to avoid possible problems?

我的问题是,最好的设计方法是什么?当然,所有这些都必须在不同的线程中发生,但我想知道的是如何以最佳方式在它们之间传递信息?我应该使用什么样的信号传递/线程锁定来避免可能的问题?

2 个解决方案

#1


I think that you could use a Queue for passing messages between the GUI and the network threads.

我认为您可以使用Queue在GUI和网络线程之间传递消息。

As for GUI and threads in general, you might find the PyGTK and Threading article interesting.

至于GUI和线程,你可能会发现PyGTK和Threading文章很有趣。

#2


One, probably the best, solution for this problem is to use Twisted. It supports all the GUI toolkits.

对于这个问题,一个可能是最好的解决方案是使用Twisted。它支持所有GUI工具包。

#1


I think that you could use a Queue for passing messages between the GUI and the network threads.

我认为您可以使用Queue在GUI和网络线程之间传递消息。

As for GUI and threads in general, you might find the PyGTK and Threading article interesting.

至于GUI和线程,你可能会发现PyGTK和Threading文章很有趣。

#2


One, probably the best, solution for this problem is to use Twisted. It supports all the GUI toolkits.

对于这个问题,一个可能是最好的解决方案是使用Twisted。它支持所有GUI工具包。