pyqt4:線程的串聯運行方式

有些時候咱們在pyqt中須要線程串行運行,而不是併發運行,用如下方式,這是在網上找的,暫存。併發

> Hello
> I have something like the foll scenario:
>
> class A(QThread):
>     def __init__(self):
>         QThread.__init__(self)
>     def run(self):
>         # do something
>         pass
> class B:
>      def __init__(self):
>          a = A()
>          a.start()
>          # a.join()               # how do i do this???
>
> Basically i want class B to "wait" till thread in class A has run
> completely. But it seems QThread does not have a ".join" method. How
> do i achieve the above?
>
> Any suggestions would be encouraging!

QThread.wait() should do what you want, i.e.,


 class B:
      def __init__(self):
          a = A()
          a.start()
          a.wait() # blocks until a's run() method has finished.
相關文章
相關標籤/搜索