13
13
from .process import (UnsupportedRequirement )
14
14
from .utils import docker_windows_path_adjust
15
15
if os .name == 'posix' and sys .version_info [0 ] < 3 :
16
- import subprocess32 as subprocess
16
+ from subprocess32 import (check_call , check_output , # pylint: disable=import-error
17
+ CalledProcessError , DEVNULL , PIPE , Popen ,
18
+ TimeoutExpired )
17
19
else :
18
- import subprocess # type: ignore
20
+ from subprocess import (check_call , check_output , # type: ignore
21
+ CalledProcessError , DEVNULL , PIPE , Popen ,
22
+ TimeoutExpired )
19
23
20
24
_logger = logging .getLogger ("cwltool" )
21
25
_USERNS = None
22
26
23
27
def _singularity_supports_userns (): # type: ()->bool
24
28
global _USERNS # pylint: disable=global-statement
25
29
if _USERNS is None :
26
- _USERNS = "No valid /bin/sh" in subprocess .run (
27
- [u"singularity" , u"exec" , u"--userns" , u"/etc" , u"true" ],
28
- stderr = subprocess .PIPE ).stderr .decode ('utf-8' )
30
+ try :
31
+ _USERNS = "No valid /bin/sh" in Popen (
32
+ [u"singularity" , u"exec" , u"--userns" , u"/etc" , u"true" ],
33
+ stderr = PIPE , stdout = DEVNULL ).communicate (timeout = 60 )[1 ]
34
+ except TimeoutExpired :
35
+ _USERNS = False
29
36
return _USERNS
30
37
31
38
@@ -92,7 +99,7 @@ def get_image(dockerRequirement, # type: Dict[Text, Text]
92
99
str (dockerRequirement ["dockerPull" ])]
93
100
_logger .info (Text (cmd ))
94
101
if not dry_run :
95
- subprocess . check_call (cmd , stdout = sys .stderr )
102
+ check_call (cmd , stdout = sys .stderr )
96
103
found = True
97
104
98
105
return found
@@ -117,8 +124,8 @@ def get_from_requirements(self,
117
124
if r :
118
125
errmsg = None
119
126
try :
120
- subprocess . check_output (["singularity" , "--version" ])
121
- except subprocess . CalledProcessError as err :
127
+ check_output (["singularity" , "--version" ])
128
+ except CalledProcessError as err :
122
129
errmsg = "Cannot execute 'singularity --version' {}" .format (err )
123
130
except OSError as err :
124
131
errmsg = "'singularity' executable not found: {}" .format (err )
0 commit comments