def example():
    proc = subprocess.Popen(['sleep', '5'], stdin=subprocess.PIPE, stdout=
        subprocess.PIPE)
with processTimeout(1, proc.pid):
    print(proc.communicate())
resultcode = proc.wait()
if resultcode < 0:
    print('error: %i' % resultcode)
if __name__ == '__main__':
    example()
Multiple subprocesses with timeouts