replace wait() subprocess method by communicate() to avoid deadlock