args = shlex.split(self.cmd)
self.process = subprocess.Popen(args, shell=True)
self.timer.start()
self.process.wait()
self.timer.cancel()

def timer_callback():
    print('Terminating process (timed out)')
self.process.terminate()
thread = threading.Thread(target=target)
self.timer = threading.Timer(timeout, timer_callback)
thread.start()
asynchronous subprocess with timeout