summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-03-23 16:42:51 (GMT)
committerGitHub <noreply@github.com>2021-03-23 16:42:51 (GMT)
commitd72e8d487553c103bf2742e229f8266b515fd951 (patch)
treec0cec7aa275f3bcb12d26e6535aaea7f3a6ad3e2 /Lib/subprocess.py
parent76b5d714e4e2b9f3b63847325cba51d4c4dc36bc (diff)
downloadcpython-d72e8d487553c103bf2742e229f8266b515fd951.zip
cpython-d72e8d487553c103bf2742e229f8266b515fd951.tar.gz
cpython-d72e8d487553c103bf2742e229f8266b515fd951.tar.bz2
bpo-41718: subprocess imports grp and pwd on demand (GH-24987)
The shutil and subprocess modules now only import the grp and pwd modules when they are needed, which is not the case by default in subprocess.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index d375514..4b011e4 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -54,14 +54,6 @@ from time import monotonic as _time
import types
try:
- import pwd
-except ImportError:
- pwd = None
-try:
- import grp
-except ImportError:
- grp = None
-try:
import fcntl
except ImportError:
fcntl = None
@@ -875,7 +867,9 @@ class Popen(object):
"current platform")
elif isinstance(group, str):
- if grp is None:
+ try:
+ import grp
+ except ImportError:
raise ValueError("The group parameter cannot be a string "
"on systems without the grp module")
@@ -901,7 +895,9 @@ class Popen(object):
gids = []
for extra_group in extra_groups:
if isinstance(extra_group, str):
- if grp is None:
+ try:
+ import grp
+ except ImportError:
raise ValueError("Items in extra_groups cannot be "
"strings on systems without the "
"grp module")
@@ -927,10 +923,11 @@ class Popen(object):
"the current platform")
elif isinstance(user, str):
- if pwd is None:
+ try:
+ import pwd
+ except ImportError:
raise ValueError("The user parameter cannot be a string "
"on systems without the pwd module")
-
uid = pwd.getpwnam(user).pw_uid
elif isinstance(user, int):
uid = user