Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
my python file closing
#1
I have 2 python files in the same directory. I have a menu that will call the 2nd python file to play a movie after choosing one. It is working fine up until I close the 2nd python file, I am not returning to my 1st python file, instead, it closes and it will finish the program. Is there a way to keep the first file open even if the user closes the second one?

in the first file in the menu i am running this function:

def play_video():
    stream = open("movie_player.py")
    read_file = stream.read()
    exec(read_file)
Note: I tried to have the 2 python files not from same directory but still the same, it is closing the 1st py file!

Thanks.
Reply
#2
Using exec() is arguably not the best way to run the other Python program. You could simply start a new process
import subprocess
import sys

def play_video():
    subprocess.Popen([sys.executable, 'movie_player.py'])
jefsummers likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to prevent Command Promt from closing when I turn it off in Python? binhduonggttn 1 2,003 Mar-06-2020, 10:12 AM
Last Post: ibreeden
  How To Find an Opening and Closing String, Copying Open/Close/Contents to New File davidshq 1 2,042 Mar-03-2020, 04:47 AM
Last Post: davidshq
  delete a file after closing it mcgrim 1 2,105 May-14-2019, 08:16 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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