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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:50:41+00:00 2026-05-25T15:50:41+00:00

I have a QThread which runs, but will often need to be killed, then

  • 0

I have a QThread which runs, but will often need to be killed, then recreated. The problem is I’m getting an untraceable TypeError that pops up and I have no idea what’s causing it. I presume I’m not exiting the thread properly or destroying it properly or some such sillyness, but I just haven’t a clue what’s causing it. Here’s some code snippets:

Here’s the code together:

class getHistory(QThread):
    def __init__(self):
        QThread.__init__(self)
        self.killSwitch = 0

    def kill(self):
        self.killSwitch = 1
        self.wait()

    def run(self):
        try:
            for x in theloop:
                hist = QTreeWidgetItem()
                hist.data = dataStuff
                self.emit(SIGNAL('histItem'), hist)
                if self.killSwitch == 1: break                
        except: pass
        self.emit(SIGNAL('string'), 'done')
        return

class Main(QtGui.QMainWindow):
    def __init__(self, args):
        QtGui.QMainWindow.__init__(self)
        self.runTheThread()

    def doFunction(self, string):
        if not string == 'done':
            doThreadStuff
        else:
            doFinishedThreadStuff

    def runTheThread(self):
        self.theThread= getHistory()
        self.connect(self.theThread, QtCore.SIGNAL("string"), self.doFunction)
        self.theThread.start()

Then to try to kill it before looping, I kill theThread with self.theThread.kill()

All the proper things as far as killing the thread appear to be happening, except, if the thread is killed and restarted fast enough, I’ll get an untraceable error:

TypeError: doFunction() takes exactly 2 arguments (1 given)

Also, on a slightly related note, is it wise/smart/right to check if a thread is done by emitting a string such as “Done” that is picked up by doFunction, or is there a better way to do it?

As doFunction is part of a Qt application, the two parameters are self, string. The code works until it is spammed, really, and only then does it present the error.

Thanks in advance.

  • 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-05-25T15:50:42+00:00Added an answer on May 25, 2026 at 3:50 pm

    Well, as error states clearly: You are sending self.doFunction just one parameter (the string “AllDone” in this case):

    self.emit(SIGNAL('string'), 'AllDone')
    

    but, I’ll take a wild guess (since you didn’t share the definition of doFunction) that it is defined as taking two parameters. So, anytime you emit the “string” signal you are bound to get that error.

    As for the signal, if it’s sole purpose is to shout that the thread is completed its run, QThread already has a “finished()” signal that is emitted when run is completed. Just use that.

    On a side note: If you are using PyQt4.5+ consider using new-style signal and slots. They are more pythonic.

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

Sidebar

Related Questions

I have a C++/Qt QThread worker thread, which stores its current status as an
I have a worker QThread in which a QObject derived object is created. The
I have a problem. I have a Qiwidget which has 2 pushbuttons. On pressing
I have the main (GUI) thread which creates a QThread. In the QThread, I
I have a QThread that contains a QUDPsocket (socket is member not local to
I have a class like this class GUI : public QWidget, public QThread When
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have a n-tire web application and search often times out after 30 secs. How
I've recently began learning about QThreads and I've a program which runs a 4
I have a QThread derived class that communicates with the main thread by sending

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.