I'm trying to close child process(which is doing while loop) when parent process is exited (Whenever parent process is clean-exit, forced-exit or exited because of exception) not to make child process a zombie process.
I'm making a game that communicates with Arduino (using serial), and main process is running Panda3D's ShowBase instance(Game engine, do render and another many things) so main must not be stopped.
So, I created subprocess using multiprocessing module so that main process is safe from stopping to wait serial in.
But the problem is, when i close Panda3D window, call sys.exit() or exited because of exception, main process exits immediately, and can't join or give false to subprocess, so subprocess becomes zombie.
I have no idea how to solve this. What should i do to make it work as i expected?
# -*- coding: utf-8 -*-
from multiprocessing import Process, Queue
from panda3d.core import *
def hardware_event_handler(self, process_status):
self.process_alive = True
self.process_alive = process_status.get()
if __name__ == '__main__':
from direct.showbase.ShowBase import ShowBase
self.process_status_argv = Queue()
self.HW_sub_process = Process(target = HW_support().hardware_event_handler, args=(self.process_status_argv,))
def exit_taskloop(self, task=None):
def task_make_alive(self, task=None):
app = TestApp()
in the main program add this at the top (well below
if multiprocessing.current_process().name == 'MainProcess': import atexit atexit.register(lambda *a : os.remove("running.txt")) open("running.txt","wb").close()
in the subprocces change your
while True loop to
alternatively you could have atexit place a message in the queue or do whatever to signal to the subprocess that it should exit.