Fix error after ending monitoring process (IOError: [Errno 32] Broken pipe)