Showing vides between processes

Hi again!

I’ve already manage to spawn new process whose job is to show vids.
When I start the application I want to show some vids in the main process, after the user press some key, I’ll spawn the new processes to show some vids, but if the user presses some more buttons I want to be able to get back to the main process and show those vids.

if __name__ == "__main__":
    global dual, midsection, tasks
    midsection = True
    #tasks = multiprocessing.JoinableQueue()
    num_consumers = 2
    consumers = [Consumer(tasks) for i in xrange(num_consumers)] # Create processes
    for w in consumers:
        w.daemon = True # If the main program dies the other processes should die with it
        w.start()
    # I should destroy the spawned processes with terminate
    # Create a wx.App(), which handles the windowing system event loop
    app = wx.App()
    width, height = wx.GetDisplaySize()
    # Create the windows containing our media players
    dual = False

    player1 = Player("Single PyVLC Player")
    player = Player("Single PyVLC Player")

    player.Centre()
    player.playFile(VIDEO1,0,True)
    player.Maximize(True)
    player.OnFullscreen(None)
    player.vidplayer1.play()
    player.Show(True)
    dual = False

    app.MainLoop()
class Consumer(multiprocessing.Process):
    def __init__(self, task_queue):
        multiprocessing.Process.__init__(self)
        self.task_queue = task_queue

    def run(self):
        app = wx.App()
        proc_name = self.name

        print "waiting for queue"

        while True: # While queue not empy
            global next_task
            next_task = self.task_queue.get()
            global dual, midsection
            midsection = next_task.d
            dual = next_task.b
            player = Player("Dual PyVLC Player")
            player.Centre()
            # show the player window centred and run the application
            print "parametro a " + str(next_task.a)
            print "parametro b " + str(next_task.b)
            print "parametro c " + str(next_task.c)
            print "parametro d " + str(next_task.d)

            player.playFile(VIDEO1,next_task.c,True) #Show one vid
            player.playFile(VIDEO2,next_task.c,False) #Show a secondvid
            player.Maximize(True)
            player.OnFullscreen(None)
            player.SetTransparent(255)

            app.MainLoop() #We need it in order to keep the videos playing but then this process is no longer reading the queue...
elif keycode == 50:
# 2 TODO Destroy process and create new one
    if dual == False: # We spawn new process and show video
        time = self.vidplayer1.get_time()
        self.vidplayer1.stop()
        self.SetTransparent(0)
        tasks.put(Task(VIDEO1, True, time, midsection))  # Put the necessary info in the queu
    else: # We destroy the spawned videos and get back to the main process
        time = self.vidplayer1.get_time()
        self.vidplayer1.stop()
        self.SetTransparent(0)
        # Stop the processes get back to main process
        # Guesses

In the else I guess I should terminate the process with terminate() and pass the info to the main process but I don’t really know how to do it.

  1. How do I kill my process?
    I’ve tried:
    sys.exit
    handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, pid)
    os.system(‘taskkill /f /im Name.exe’)
    to no avail

  2. If I have finished all the new process I should be able to put in the queue the data and wait for the main process to read it, but once again how do I stop the main process from displaying the videos and start reading?
    Is there a way to know how many children are alive?

Thanks for the help!

···