>>> import subprocess subprocess.py:398: RuntimeWarning: The _posixsubprocess module is not being used. Child process reliability may suffer if your program uses threads. "program uses threads.", RuntimeWarning) >>> p = subprocess.Popen("tcpdump -i eth0 > file &", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True) >>> try: ... print(1) ... out, err = p.communicate('', timeout=1) ... except subprocess.TimeoutExpired: ... print(2) ... p.kill() ... print(3) ... out, err = p.communicate() ... print(4) ... 1 2 3 Traceback (most recent call last): File "", line 3, in File "subprocess.py", line 775, in communicate stdout, stderr = self._communicate(input, endtime) File "subprocess.py", line 1414, in _communicate stdout, stderr = self._communicate_with_poll(input, endtime) File "subprocess.py", line 1490, in _communicate_with_poll self._check_timeout(endtime) File "subprocess.py", line 801, in _check_timeout raise TimeoutExpired(self.args) subprocess.TimeoutExpired During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 8, in File "subprocess.py", line 775, in communicate stdout, stderr = self._communicate(input, endtime) File "subprocess.py", line 1414, in _communicate stdout, stderr = self._communicate_with_poll(input, endtime) File "subprocess.py", line 1469, in _communicate_with_poll register_and_append(self.stdout, select_POLLIN_POLLPRI) File "subprocess.py", line 1448, in register_and_append poller.register(file_obj.fileno(), eventmask) ValueError: I/O operation on closed file