Python Forum
Launch pdf and close on delete window event
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Launch pdf and close on delete window event
#5
Ok here is the code I have now. I use multiprocessing to launch the pdf, however it's still not closing my file.
def LaunchPDF(filename):
    """
    Launches PDF by filename and tracks PID
    @param filename, the name of the file to launch
    @return None
    """
    print(filename)
    os.startfile(filename)

def QueryShubertFiles(self):
    """
    Queries the blob data from table based on filename.
    @param, self the App object.
    @return None.
    """
    for element in self.SectionList.curselection():
       value = self.Query("SELECT Data FROM ShubertDocs WHERE Filename = '" + self.SectionList.get(element) + "';")
       if ".JPG" in self.SectionList.get(element):
           bio = BytesIO(value[0][0])
           Image.open(bio).show()
       elif ".PDF" in self.SectionList.get(element) or ".pdf" in self.SectionList.get(element):
           #track files saved to disk
           self.saved_files.append(self.SectionList.get(element))
           try:
               with open(self.SectionList.get(element), 'wb') as f:
                   f.write(value[0][0])
           except:
               pass
           #doc = Popen("start /WAIT " + self.SectionList.get(element), shell=True)
           self.processes.append(multiprocessing.Process(target=LaunchPDF, args=(self.SectionList.get(element),)))
           self.processes[-1].start()


def on_closing(self):
        self.window.destroy()
        
        ## wait 2 seconds and kill all processes
        time.sleep(2)
        print(self.processes)
        for process in self.processes:
            process.terminate()
            process.join()
            print(process, "terminated")

        #clean up 
        for file in self.saved_files:
            os.remove(file)
When I print the processes it tells me they are all stopped, then when I attempt to remove the files I receive a process is still being used. The pdf never closes.
Reply


Messages In This Thread
RE: Launch pdf and close on delete window event - by ashtona - Mar-22-2018, 12:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 652 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [PyQt] command require close window Krissstian 14 3,160 Nov-19-2022, 04:18 PM
Last Post: Krissstian
  [Tkinter] Mouse click event not working on multiple tkinter window evrydaywannabe 2 3,815 Dec-16-2019, 04:47 AM
Last Post: woooee
  tkinter window and turtle window error 1885 3 6,807 Nov-02-2019, 12:18 PM
Last Post: 1885
  update a variable in parent window after closing its toplevel window gray 5 9,191 Mar-20-2017, 10:35 PM
Last Post: Larz60+
  pygtk2, how to disconnect all callback of widget or window event ? harun2525 1 3,356 Feb-19-2017, 11:44 PM
Last Post: Larz60+
  [Tkinter] I have a Toplevel button in tkinker that I want to close the window and then perform Bloodypizza17 2 7,853 Jan-06-2017, 07:18 PM
Last Post: Bloodypizza17
  launch .PY program Help iw2fo 22 20,333 Oct-18-2016, 09:13 PM
Last Post: Barrowman

Forum Jump:

User Panel Messages

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