Brian Hamilton
Brian Hamilton

Reputation: 11

Restarting Python program to clear data

I have a program made up of 4 different .py files.

A Tkinter GUI, a Functions File, A plotly Map file, and a reference one just for some variables to use for export that are static.

First, is a Tkinter GUI. It has 4 buttons

  1. Import a Log
  2. Import a Report template
  3. Generate the Report
  4. Clear Data

As I want to generate a report, then select a new log, new template and generate it again I have to either restart the program, or find a way to clear all the variables so it can read the second log.

The issue I am having is, that I have it working inside VSCODE. If I press "Clear Data" It clears the data, I can select a new log and report.

However, after creating an EXE using pyinstaller it does not work. It will close the Tkinter gui, then the terminal window right after.

Below are options I have tried.

def restart_program():
    os.execl(sys.executable, sys.executable, *sys.argv)
def restart_program():
    exe_path = sys.executable
    subprocess.Popen(["timeout", "1", "&&", exe_path], shell=True)
    sys.exit()

All results are the same. It fully closes the EXE and doesnt reopen.

So I am asking, what am I doing wrong? Is there a better way to do this? Do I need to actually restart the EXE to clear the variables, or is there a way to just wipe all the data/variables from the first log import using a "clear data" function?

def restart_program():
    exe_path = sys.executable  # Path to the EXE when compiled
    subprocess.Popen([exe_path])  # Restart the EXE
    sys.exit()

Upvotes: 0

Views: 36

Answers (0)

Related Questions