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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:31:30+00:00 2026-05-26T09:31:30+00:00

I have a relatively large application written in Python and using PyQT as a

  • 0

I have a relatively large application written in Python and using PyQT as a GUI frontend. The entire application is in one class, in one file.

Here’s an example code:

class Application(QMainWindow):
  def __init__(self):
    super(etc...)

    self.connect(self.mainBtn, SIGNAL("clicked()"), self.do_stuff)

  def do_stuff(self):
    <checking some parameters>
    else:
      do_some_other_long_stuff()


  def do_some_other_long_stuff(self):
     500 lines of code of stuff doing

However, this is the problem: when I click the mainBtn, everything goes fine, except the GUI kind of freezes – I can’t do anything else until the function is performed (and it’s a web scraper so it takes quite a bit of time). When the function do_some_other_long_stuff ends, everything goes back to normal. This is really irritating.

Is there a way to somehow “background” the do_some_other_stuff process? I looked into QThreads and it seems it does just that, however that would require me to rewrite basically all of code, put half of my program in a different class, and therefore have to change all the variable names (when getting a variable from GUI class and putting it in working class)

  • 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-26T09:31:31+00:00Added an answer on May 26, 2026 at 9:31 am

    Duplicate of Handling gui with different threads,
    How to keep track of thread progress in Python without freezing the PyQt GUI?, etc.

    Your do_stuff() function needs to start up the computing thread and then return. Multi-threading is the name given to running multiple activities in a single process – by definition if something is going on “in the background”, it’s running on a separate thread. But you don’t need to split functions into a different classes to use threads, just be sure that the computing functions don’t do anything with the GUI and the main thread doesn’t call any of the functions used by the computing thread.

    EDIT 10/23: Here’s a silly example of running threads in a single class – nothing in the language or the threading library requires a different class for each thread. The examples probably use a separate class for processing to illustrate good modular programming.

    from tkinter import *
    import threading
    
    class MyApp:
        def __init__(self, root):
            self.root = root
            self.timer_evt = threading.Event()
            cf = Frame(root, borderwidth=1, relief="raised")
            cf.pack()
            Button(cf, text="Run", command=self.Run).pack(fill=X)
            Button(cf, text="Pause", command=self.Pause).pack(fill=X)
            Button(cf, text="Kill", command=self.Kill).pack(fill=X)
    
        def process_stuff(self):        # processing threads
            while self.go:
                print("Spam... ")
                self.timer_evt.wait()
                self.timer_evt.clear()
    
        def Run(self):                  # start another thread
            self.go = 1
            threading.Thread(target=self.process_stuff, name="_proc").start()
            self.root.after(0, self.tick)
    
        def Pause(self):
            self.go = 0
    
        def Kill(self):                 # wake threads up so they can die
            self.go = 0
            self.timer_evt.set()
    
        def tick(self):
            if self.go:
                self.timer_evt.set()    # unblock processing threads
                self.root.after(1000, self.tick)
    
    def main():
        root = Tk()
        root.title("ProcessingThread")
        app = MyApp(root)
        root.mainloop()
    
    main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively large csv/text data file (33mb) that I need to do
We have a relatively large web application (>200 pages) to which we need to
We have a relatively large application that is strongly tied into Firebird (stored procedures,
I have a small application that process a large quantity of (relatively small) files.
I have a relatively large database tables (just under a million rows) that has
I have a need to run a relatively large number of virtual machines on
I have a relatively complex .htaccess file to control page requests, this currently redirects
I have a relatively simple form which asks a variety of questions. One of
I have a relatively small app that Im building using vb.net 2.0, and nant.
I have a relatively simple application which I need to make native Mac OSX

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.