0

StackOverflow community. I am writing a python GUI to monitor another program's data in OSX environment and at one point I decide to click one button to open another python script that I wrote. It does work but it also causes a lag problem of the main GUI program as soon as I click the button. For the lag problem I mean the GUI window is "Not Responding" and I need to force quit. The method I use to run the new script is,

def create_html():
os.system('python realtime.py')

My program doesn't have the multiple class structure, just the simple canvas, and framework. I wonder if this is also the problem to cause my program running slow.

Peter Wang
  • 11
  • 1

1 Answers1

0

The problem is you are using os.system, which is a blocking call. It will not return control to your main code until python realtime.py is done executing and returned.

You need to use a call that will not block the rest of your program, such as subprocess.Popen.

You can also see this QA for further information

ritlew
  • 1,622
  • 11
  • 13
  • Is there a method to make the file that I want to subprocess.Popen be on top of the main GUI program? – Peter Wang Jul 19 '18 at 19:41
  • Not easily. Usually `Popen` and the like are used to call command line programs that do not have a GUI. No easy built-in controls exist to do what you want, but you could do something more complicated with OS bindings to manipulate windows. – ritlew Jul 19 '18 at 19:43