Refactoring of code in reporting to avoid multiprocessing deadlock