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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:05:19+00:00 2026-06-01T11:05:19+00:00

I was researching for some time to find information how to do multithreaded program

  • 0

I was researching for some time to find information how to do multithreaded program using PyQT, updating GUI to show the results.

I’m used to learning by example and i can’t find (yes i was looking for weeks) any simple example of program using multithreading doing such simple task as for example connecting to list of www sites (5 threads) and just printing processed urls with response code.

Could anyone share code or send me to good tutorial where such program is explained ?

  • 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-01T11:05:20+00:00Added an answer on June 1, 2026 at 11:05 am

    Here some very basic examples.


    You can pass references to GUI elements to threads, and update them in thread.

    import sys
    import urllib2
    
    from PyQt4 import QtCore, QtGui
    
    
    class DownloadThread(QtCore.QThread):
        def __init__(self, url, list_widget):
            QtCore.QThread.__init__(self)
            self.url = url
            self.list_widget = list_widget
    
        def run(self):
            info = urllib2.urlopen(self.url).info()
            self.list_widget.addItem('%s\n%s' % (self.url, info))
    
    
    class MainWindow(QtGui.QWidget):
        def __init__(self):
            super(MainWindow, self).__init__()
            self.list_widget = QtGui.QListWidget()
            self.button = QtGui.QPushButton("Start")
            self.button.clicked.connect(self.start_download)
            layout = QtGui.QVBoxLayout()
            layout.addWidget(self.button)
            layout.addWidget(self.list_widget)
            self.setLayout(layout)
    
        def start_download(self):
            urls = ['http://google.com', 'http://twitter.com', 'http://yandex.ru',
                    'http://stackoverflow.com/', 'http://www.youtube.com/']
            self.threads = []
            for url in urls:
                downloader = DownloadThread(url, self.list_widget)
                self.threads.append(downloader)
                downloader.start()
    
    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        window = MainWindow()
        window.resize(640, 480)
        window.show()
        sys.exit(app.exec_())
    

    Editors Note: Qt widgets are not thread safe and should not be accessed from any thread but the main thread (see the Qt documentation for more details). The correct way to use threads is via signals/slots as the second part of this answer shows.


    Also, you can use signals and slots, to separate gui and network logic.

    import sys
    import urllib2
    
    from PyQt4 import QtCore, QtGui
    
    
    class DownloadThread(QtCore.QThread):
    
        data_downloaded = QtCore.pyqtSignal(object)
    
        def __init__(self, url):
            QtCore.QThread.__init__(self)
            self.url = url
    
        def run(self):
            info = urllib2.urlopen(self.url).info()
            self.data_downloaded.emit('%s\n%s' % (self.url, info))
    
    
    class MainWindow(QtGui.QWidget):
        def __init__(self):
            super(MainWindow, self).__init__()
            self.list_widget = QtGui.QListWidget()
            self.button = QtGui.QPushButton("Start")
            self.button.clicked.connect(self.start_download)
            layout = QtGui.QVBoxLayout()
            layout.addWidget(self.button)
            layout.addWidget(self.list_widget)
            self.setLayout(layout)
    
        def start_download(self):
            urls = ['http://google.com', 'http://twitter.com', 'http://yandex.ru',
                    'http://stackoverflow.com/', 'http://www.youtube.com/']
            self.threads = []
            for url in urls:
                downloader = DownloadThread(url)
                downloader.data_downloaded.connect(self.on_data_ready)
                self.threads.append(downloader)
                downloader.start()
    
        def on_data_ready(self, data):
            print data
            self.list_widget.addItem(unicode(data))
    
    
    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        window = MainWindow()
        window.resize(640, 480)
        window.show()
        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've spent some time researching this and simply can't find a definitive answer. Here
I've spent some time researching how to communicate with SAP from a PHP web
I've spent some time researching this and still can't figure it out. It seem
I've currently been learning Objective-C and Cocoa for some time but I feel that
I'm having a tough time learning Javascript/Ext-JS. I setup the Spket plug-in for some
I've been researching this for quite long time now, can't find the answer. How
I spent quite some time researching for a library that allows me to compare
I have spent some time researching Android's ability to communicate with bluetooth devices that
A project I'm researching requires some numerical pattern matching. My searches haven't turned up
I have been researching and have some few ideas about a distributed caching system

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.