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

  • Home
  • SEARCH
  • 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 8994899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:31:31+00:00 2026-06-15T23:31:31+00:00

I have a situation where i need to start two threads one after the

  • 0

I have a situation where i need to start two threads one after the other. I tried the following code snippet, here i could able to start the Thread12 but not able to start Thread2. How can i start both….?
How to start 2 threads one ofter the other…?

Code snippet

class Thread1(QtCore.QThread):

    Thread1Signal = QtCore.pyqtSignal(str)

    def __init__(self):
        super(Thread1, self).__init__()

    def run(self):
        print 'Thread1 started'
        While True:

            #some statments
            if Condition:
                Thread1Signal.emit('Yes')
            else:
                Thread1Signal.emit('No')

class Thread2(QtCore.QThread):

    Thread2Signal = QtCore.pyqtSignal(str)

    def __init__(self):
        super(Thread2, self).__init__()

    def run(self):
        print 'Thread2 started'
        While True:

            #some statments
            if Condition:
                Thread2Signal.emit('Yes')
            else:
                Thread2Signal.emit('No')

class MainClass(QtCore.QObject):

    MainSignal1 = QtCore.pyqtSignal(str)
    MainSignal2 = QtCore.pyqtSignal(str)

    def __init__(self):
        super(MainClass, self).__init__()   

        Threadinstance1 = Thread1()
        Threadinstance1.Thread1Signal.connect(MainSignal1)

        Threadinstance2 = Thread2()
        Threadinstance2.Thread2Signal.connect(MainSignal2)


   def start(self):

       Threadinstance1.start()
       Threadinstance2.start()                #Thread2 never starts.

def signal1called(s):

    print s


def signal2called(s):

    print s

if __name__=='__main__':
    app = AtGui.QApplication(sys.argv)
    temp = MainClass()
    temp.MainSignal1.connect(signal1called)
    temp.MainSignal2.connect(signal2called)
    temp.start()
    sys.exit(app.exec()_)
  • 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-15T23:31:32+00:00Added an answer on June 15, 2026 at 11:31 pm

    You will be using QRunnable and QThreadPool, something like this:

    import sys
    
    from PyQt4.QtGui import QApplication
    from PyQt4.QtCore import QThreadPool, QObject, QRunnable, pyqtSignal
    
    class WorkerSignals(QObject):
        result = pyqtSignal(int)
    
    class Worker(QRunnable):
        def __init__(self, task):
            super(Worker, self).__init__()
    
            self.task = task
            self.signals = WorkerSignals()
    
        def run(self):
            print 'Sending', self.task
            self.signals.result.emit(self.task)
    
    class Tasks(QObject):
        def __init__(self):
            super(Tasks, self).__init__()
    
            self.pool = QThreadPool()
            self.pool.setMaxThreadCount(1)
    
        def process_result(self, task):
            print 'Receiving', task
    
        def start(self):
            for task in range(10):
                worker = Worker(task)
                worker.signals.result.connect(self.process_result)
    
                self.pool.start(worker)
    
            self.pool.waitForDone()
    
    if __name__ == "__main__":
        import  sys
    
        app = QApplication(sys.argv)
        main = Tasks()
        main.start()
        sys.exit(app.exec_())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where I need to pass two parameters to an action.
I have a situation where I need to hide the taskbar and start button
I have a situation where I need to check if the other side of
I have the following situation. I have an application that runs mostly on one
I have two dates - a start date and an end date. I need
Let me explain the situation I have two tables: -One is to store the
I have situation when one of tables rich size 2G and after it I
Ok, so I have the following situation. I need to edit the PYTHONPATH dynamically
I have situation where I need to change the order of the columns/adding new
I have a situation where I need to dynamically build up a list of

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.