Avoid race condition in multiprocessing cleanup.