summaryrefslogtreecommitdiff
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-07-05 22:54:17 +0200
committerGitHub <noreply@github.com>2018-07-05 22:54:17 +0200
commit483422f57e5d8c8bf8820fec29fc9b96bb15d4ef (patch)
tree236c127b825436f6f16d04bc57ef89a58706a70f /Lib/subprocess.py
parent09bb918a61031377d720f1a0fa1fe53c962791b6 (diff)
downloadcpython-git-483422f57e5d8c8bf8820fec29fc9b96bb15d4ef.tar.gz
bpo-34044: subprocess.Popen copies startupinfo (GH-8090)
subprocess.Popen now copies the startupinfo argument to leave it unchanged: it will modify the copy, so that the same STARTUPINFO object can be used multiple times. Add subprocess.STARTUPINFO.copy() method.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 93635ee61f..e070011d98 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -135,6 +135,19 @@ if _mswindows:
self.hStdError = hStdError
self.wShowWindow = wShowWindow
self.lpAttributeList = lpAttributeList or {"handle_list": []}
+
+ def copy(self):
+ attr_list = self.lpAttributeList.copy()
+ if 'handle_list' in attr_list:
+ attr_list['handle_list'] = list(attr_list['handle_list'])
+
+ return STARTUPINFO(dwFlags=self.dwFlags,
+ hStdInput=self.hStdInput,
+ hStdOutput=self.hStdOutput,
+ hStdError=self.hStdError,
+ wShowWindow=self.wShowWindow,
+ lpAttributeList=attr_list)
+
else:
import _posixsubprocess
import select
@@ -1102,6 +1115,10 @@ class Popen(object):
# Process startup details
if startupinfo is None:
startupinfo = STARTUPINFO()
+ else:
+ # bpo-34044: Copy STARTUPINFO since it is modified above,
+ # so the caller can reuse it multiple times.
+ startupinfo = startupinfo.copy()
use_std_handles = -1 not in (p2cread, c2pwrite, errwrite)
if use_std_handles: