Replit can't seem to run a subprocess.Popen() code

Crash on subprocess.Popen()

Repl link/Link to where the bug appears:

Screenshots, links, or other helpful context:
I don’t know why its doing this, but I have this very simple code that tries to run a subprocess.Popen() line upon pressing a button. However, when it does, it dosen’t open the second python file. When I use a run() or call() it works, but the Popen dosen’t. I need to use Popen as it allows me to program to continue running after opening the second file.

Why is it doing this?

import tkinter as tk
import subprocess
import sys

def start_newFile():

    #this code works, 'main (copy).py'))

    #this dosen't
    subprocess.Popen((sys.executable, 'main (copy).py'))

root = tk.Tk()
root.title("First Script")

# Function to start a new file
def start_new_file():

# Button to start a new file
start_button = tk.Button(root, text="Start New File", command=start_new_file)


To clarify further, I need to be able to open up a second python file while closing the previous one. Popen() is the only function that works in this regard as it allows the sys.exit() to run.

I need this done for a project requirement, however, the Popen() function dosen’t work as intended. If I were to do this on say Thonny it works fine and as intended. It opens the second python file and closes the first one.

but when I try to do this in replit it dosen’t work.

Hi @rbustamante6787 , welcome to the forums!
Instead of using sys.exit(), which may cause errors on Replit, let the program exit on its own. Try removing the sys.exit() line.
Hope this helps!

1 Like