Search code examples
pythonperformanceuser-interfacelag

Python GUI using os.system to run python script cause main GUI "Not Responding"


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.


Solution

  • 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