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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:39:36+00:00 2026-05-20T09:39:36+00:00

I am creating a GUI application(wxPython). I need to run another (.exe) application from

  • 0

I am creating a GUI application(wxPython). I need to run another (.exe) application from the GUI application. The subprocess will perform some operation on a user action and return an output to the GUI application

I am running this subprocess in a loop, so that constantly the subprocess is available to execute. What I am doing is, I start a thread(so gui does not freeze) and popen the
subprocess in a loop. Not sure if this is the best way.

self.thread = threading.Thread(target=self.run, args=())
self.thread.setDaemon(True)
self.thread.start()

def run(self):
        while self.is_listening:
            cmd = ['application.exe']
            proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
            proc.wait()
            data = ""
            while True:
                txt = proc.stdout.readline()
                    data = txt[5:].strip()
                    txt += data

Now what happens is, if the main application is shutdown, the thread is still waiting for a user action which never came. How can I exit cleanly? The application.exe process can still be seen in the process list, even after GUI app has exited. Any suggestions to improve the whole thing are welcome.

thanks

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

    1) Make ‘proc’ a instance attribute, so you can call it’s terminate() or kill() methods before exiting.

    self.thread = threading.Thread(target=self.run, args=())
    self.thread.setDaemon(True)
    self.thread.start()
    
    def run(self):
        while self.is_listening:
            cmd = ['application.exe']
            self.proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
            self.proc.wait()
            data = ""
            while True:
                txt = self.proc.stdout.readline()
                data = txt[5:].strip()
                txt += data
    

    2) Use some variable to tell the thread to stop (You will need to use poll() in a loop, instead of using wait()).

    self.exit = False
    self.thread = threading.Thread(target=self.run, args=())
    self.thread.setDaemon(True)
    self.thread.start()
    
    def run(self):
        while self.is_listening:
            cmd = ['application.exe']
            proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
            while proc.poll() is None or not self.exit:
                pass
            data = ""
            while True:
                if self.exit:
                    break
                txt = proc.stdout.readline()
                data = txt[5:].strip()
                txt += data
    

    The ‘atexit’ module documentation can help you with calling things at exit.

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

Sidebar

Related Questions

I'm creating a GUI application which interacts with database so I need fixture management
I'm implementing a GUI for a console application, and I need to do some
I'm writing a Qt GUI Application, but there's a strange error i can't figure
I've been analyzing a WPF application which basically fetch data from a server and
I am from Java Swing background. May I know why using XML to create
I am in the process of creating my first iPhone app. The app currently
I've got a for loop I want to parallelize with something like PLINQ's Parallel.ForEach().
How can I create a custom windows message that passes any data to a
I've been studying and experimenting on c language with c99 standard for almost 3

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.