"使用多线程的情况下GUI仍然卡死"

2024-06-07 17:04:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写电子邮件申请。当我发送电子邮件时,我的主GUI线程甚至挂起,我创建了一个单独的线程来发送电子邮件。我想我错过了理解线程?在

我在主线程的开头有一个GObject函数start_init()。我不需要threads_enter()和threads_leave(),因为线程正在对我的GUI进行更改。在

我知道有很多关于线程的问题,但作为一个初学者,我无法理解它们。我做错什么了?在

类发送电子邮件

class EmailSendThread(Thread):

  def __init__(this, email):
    Thread.__init__(this)
    this.email = email


  def run(this):
    this.email.send_email()

按“发送”按钮

^{pr2}$

应用程序初始化

GObject.threads_init()
EasyMail = EasyMailApplication()

Gtk.main()

Tags: 函数init电子邮件emaildefguithis线程

热门问题