即使在使用线程pygtk之后,GUI也会挂起

时间:2014-10-21 16:31:53

标签: python multithreading multiprocessing pygtk gtk3

我正在写一封电子邮件应用程序。当我发送电子邮件时,我的主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()

按钮发送按

def on_btn_Send_clicked(this, *args):

  Ethread = EmailSendThread(this.application.email)
  Ethread.setName('SendEmailThread')

  Ethread.start()
  Ethread.join()

申请初始

GObject.threads_init()
EasyMail = EasyMailApplication()

Gtk.main()

1 个答案:

答案 0 :(得分:0)

Thread.join使主程序等待,直到线程完成执行。如果您不希望主程序在那里等待,请不要致电join