Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9093735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:10:42+00:00 2026-06-16T23:10:42+00:00

I have i python application, which uses PyQt GUI. It application has some I/O

  • 0

I have i python application, which uses PyQt GUI. It application has some I/O operations, which i want to run in separate threads.
When each thread started, it should write messages to applications main window status bar and when last thread is completed, status bar messages should be cleared.
How can i handle number of threads via QThread?

Here is example of code:

import sys, time
from PyQt4 import QtCore, QtGui
from functools import partial


def io_emulator(sleep_seconds):
    print 'We will sleep for %s seconds' % str(sleep_seconds)
    time.sleep(sleep_seconds)


class IOThread(QtCore.QThread):
    def __init__(self, func):
        QtCore.QThread.__init__(self)
        self.io_func = func

    def run(self):
        self.io_func()


class m_Window(QtGui.QWidget):
    def __init__(self):
        super(m_Window, self).__init__()

        self.initUI()

    def initUI(self):
        self.thread_button = QtGui.QPushButton("Thread", self)
        self.thread_button.move(30, 10)
        self.spinbox = QtGui.QSpinBox(self)
        self.spinbox.move(30, 50)
        self.stat_label = QtGui.QLabel("", self)
        self.stat_label.setGeometry(QtCore.QRect(200, 200, 150, 14))
        self.stat_label.move(30,90)

        self.setWindowTitle('Threads')
        self.show()

        self.thread_button.clicked.connect(self._sleeper)

    def _sleeper(self):
        seconds = int(self.spinbox.text())
        stat_str = 'Sleeping %s seconds' % str(seconds)

        io_func = partial(io_emulator, seconds)
        set_status_f = partial(self.set_status_msg, stat_str)

        self.thread =  IOThread(io_func)
        self.thread.started.connect(set_status_f)
        self.thread.finished.connect(self.clear_status_msg)

        self.thread.start()

    def set_status_msg(self, msg):
        self.stat_label.setText(msg)

    def clear_status_msg(self):
        self.stat_label.clear()


def main():
    app = QtGui.QApplication(sys.argv)
    m = m_Window()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

I want, that message is being cleared only when last thread is ended.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:10:43+00:00Added an answer on June 16, 2026 at 11:10 pm

    You cannot call QWidget functions from any thread but the main thread. If you want another thread to trigger GUI operations, then they should be communicated by emitting signals that are connected to your main thread:

    def someFunc():
        return "message"
    
    class IOThread(QtCore.QThread):
    
        statusUpdate = QtCore.pyqtSignal(str)
    
        def __init__(self, func):
            QtCore.QThread.__init__(self)
            self.io_func = func
    
        def run(self):
            msg = self.io_func()
            self.statusUpdate.emit(msg)
    

    Then in your main thread, connect the io thread to the status label or some intermediate handler:

    io_thread = IOThread(someFunc)
    io_thread.statusUpdate.connect(self.status_label.setText)
    

    This will create a queued connection, which places the call into the event loop of the main thread for execution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python application which uses a compiled shared library. This library for
I have a python application which need a gui HTML editor, I know FCKeditor
I have a Pyramid application which uses request.environ['REMOTE_ADDR'] in some places. The application is
I have a App Engine/Python/Django application which has grown and been modified over the
I have to build a web application which uses Python, php and MongoDB. Python
I have a C++ application which uses the Core, GUI and Network modules of
I have a Python application in which I would like to monitor the number
I have a python (pygtk) application which starts in different modes depending on arguments.
In my Python application I have some GtkMenuItems (associated with the main GtkMenuBar), and
I have a multi threaded python application communicating with a separate service trough UDP.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.