human
Complete the below
def ensure_proc_terminate(proc):

    ''''Make sure processes terminate when main process exit.
    Args:
    proc (multiprocessing.Process or list)'
    '''

Give me a the Python code you requested?
assistant
#Here is the Python code you requested.
    if isinstance(proc, list):
        for p in proc:
            ensure_proc_terminate(p)
        return
    def stop_proc_by_weak_ref(ref):
        proc = ref()
        if (proc is None):
            return
        if (not proc.is_alive()):
            return
        proc.terminate()
        proc.join()
    assert isinstance(proc, multiprocessing.Process)
    atexit.register(stop_proc_by_weak_ref, weakref.ref(proc))