Python Forum
[PyQt] How to open a program with python without freezing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] How to open a program with python without freezing
#4
I am using PyQt. I have tried to use subprocess.run() and subprocess.call(). From what I understand is that it executes a command, but then waits for it to exit before I can continue and I don't want it to wait. I need it to run the program/file then allow me to also run other commands. A good way to describe what I want to do is basically create a program like the start menu in windows. Here is an example of some code that I tried where I create a new thread for launching programs.
class thread(QtCore.QThread):
    def __init__(self):
        super(thread, self).__init__()
        self.program = ''#path to program
        self.target = ''#path to file for program to open
    def run(self):
        while True:
            print('-')#prints when loop runs. Shows that loop stops after command executed until you close the created process
            if self.Program != '':
                call(r'%s' % self.program)#runs command
                self.program = ''#resets
            time.sleep(0.7)#Prevents CPU use by waiting a short time between runs
If I set the program to 'explorer' then the loop does not freeze, but I can't set a target file if I set the program to 'explorer' because I would have to set the target as the program I want to run so I won't be able to set a target file. Or I use explorer to open a file but It will only open with the default program set to open it.
Reply


Messages In This Thread
RE: How to open a program with python without freezing - by LavaCreeperKing - Aug-13-2019, 03:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Open a python program from a button Pedroski55 3 5,078 Jul-20-2020, 11:09 PM
Last Post: Pedroski55
  [Tkinter] GUI keeps freezing Fre3k 2 3,637 May-23-2020, 05:41 PM
Last Post: Fre3k
  [Tkinter] How to create a delay for AI without freezing the GUI kom2 8 6,228 May-04-2019, 02:32 PM
Last Post: Yoriz
  Gi module window freezing problem loss 0 2,251 May-05-2018, 04:42 PM
Last Post: loss

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020