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 8899825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:57:09+00:00 2026-06-15T00:57:09+00:00

I am building an application with a GUI and several worker threads. Now I

  • 0

I am building an application with a GUI and several worker threads. Now I want it to be a multi-threaded application so I am executing the same thread several times, in a loop, each thread grabbing different input parameters defined in a class outside of the thread.

So my mainGui.py file looks something like this (relevant code shown only):

self.workers = [worker.Worker(), worker.Worker(), worker.Worker()]
for i in xrange(threadCount):
    self.currentWorker = self.workers[i]
    self.currentWorker.alterTable.connect(self.alterMainTable)
    self.currentWorker.start()
    time.sleep(0.1)

As you may imagine, I am connecting the Worker’s alterTable signal to the alterMainTable() method I have defined in my main GUI thread. This method updates the table in the GUI.

The worker thread looks something like this:

class Worker(QThread):

    alterTable = Signal(dict)

    def __init__(self, parent=None):
        super(Worker, self).__init__(parent)

    def sendToTable(self, param1, param2, param3):
        """This method emits the signal with params as defined above"""
        params = {}
        params["param1"] = param1
        params["param2"] = param2
        params["param3"] = param3
        self.alterTable.emit(params)

    def run(self):
        #Perform a lengthy task, do this every now and then:
        self.sendToTable(param, param2, param3)

When I am running this application in a single worker thread (so when I’m not calling that loop in the main thread), it works fine – the signals are emitted, and the main table in the GUI is updated.

However, the problems arise when I run several threads at once. The Worker threads do their job, but the Signal is only emitted sometimes. Or, better yet, it is emitted as if Qt (or whatever) was waiting for all the threads to finish, and then update the table. This is literally what happens – I can see in Python console that the threads are performing their tasks, and once all of them are doing whatever they were doing, the table is suddenly populated with a bunch of data at once.

As you may imagine, another problem that comes out of this is that since there are no events being processed, after some time, my application appears to be frozen.

I have tried adding the Qt.DirectConnection to the connect() method, but that didn’t really help.

Bonus question: I’ve been reading about this topic on SO and other websites, it seems that people recommend QRunnable() instead of QThread() especially when it comes to subclassing it. Consequently, I’d be using QThreadPool(). But when I tried this, it seems that I cannot emit a signal from a QRunnable – it gives me the AttributeError: 'PySide.QtCore.Signal' object has no attribute 'connect', even though the Signal is defined within the QRunnable class – which is quite odd, I must say.

EDIT: In another answer on SO, someone mentioned that one may be “spamming” the main GUI thread with events to be processed. However, I don’t believe that this is the case here as the sendToTable() method from the QThread is only called 5-6 times at most from the thread, and the threadCount is never larger than 20 at most, but I usually keep it at around 5.

  • 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-15T00:57:10+00:00Added an answer on June 15, 2026 at 12:57 am

    And, as usual, I answer my question after 2 days of debugging and minutes after posting on SO.

    I had a leftover workerThread.wait() method call after all the threads have been started. So naturally my application did what it was told to do – waited for the thread to finish.

    I removed that method call and also put the QCoreApplication.processEvents() inside the loop which started the threads, now it all works like a charm.

    Once again, thank you, the invisible, almighty person of SO!

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

Sidebar

Related Questions

After building the application GUI, I realised it was a little bit too complex
I'm building an application for a linux platform in C, with a GTK+2 GUI.
I'm building an application, it's easy and what I want to do is the
I am working on building a GUI around a console application. I would like
I'm currently tasked with building a spreadsheet-like GUI for a WPF application and I've
I'm building a Java application with a Swing GUI and a task that takes
I'm building a small GUI-Test automation tool in C# for a application. One of
I am building a simple wpf application. The gui has a button, that when
I am building a QT GUI application and use QImage for opening images. My
I'm building a GUI application and try to adhere to the MVC principle as

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.