@@ -1012,35 +1012,34 @@ def executable(self):
1012
1012
self ._logger .warning ("Chrome executable not found" )
1013
1013
raise unittest .SkipTest ("Chrome executable not found" )
1014
1014
1015
- def _spawn_chrome (self , cmd ):
1016
- if os .name == 'nt' :
1017
- proc = subprocess .Popen (cmd , stderr = subprocess .DEVNULL )
1018
- pid = proc .pid
1019
- else :
1020
- pid = os .fork ()
1021
- if pid != 0 :
1022
- port_file = pathlib .Path (self .user_data_dir , 'DevToolsActivePort' )
1023
- for _ in range (100 ):
1024
- time .sleep (0.1 )
1025
- if port_file .is_file () and port_file .stat ().st_size > 5 :
1026
- with port_file .open ('r' , encoding = 'utf-8' ) as f :
1027
- self .devtools_port = int (f .readline ())
1028
- break
1029
- else :
1030
- raise unittest .SkipTest ('Failed to detect chrome devtools port after 2.5s.' )
1031
- return pid
1032
- else :
1033
- if platform .system () != 'Darwin' :
1034
- # since the introduction of pointer compression in Chrome 80 (v8 v8.0),
1035
- # the memory reservation algorithm requires more than 8GiB of virtual mem for alignment
1036
- # this exceeds our default memory limits.
1037
- # OSX already reserve huge memory for processes
1015
+ def _chrome_without_limit (self , cmd ):
1016
+ if os .name == 'posix' and platform .system () != 'Darwin' :
1017
+ # since the introduction of pointer compression in Chrome 80 (v8 v8.0),
1018
+ # the memory reservation algorithm requires more than 8GiB of
1019
+ # virtual mem for alignment this exceeds our default memory limits.
1020
+ def preexec ():
1038
1021
import resource
1039
1022
resource .setrlimit (resource .RLIMIT_AS , (resource .RLIM_INFINITY , resource .RLIM_INFINITY ))
1040
- # redirect browser stderr to /dev/null
1041
- with open (os .devnull , 'wb' , 0 ) as stderr_replacement :
1042
- os .dup2 (stderr_replacement .fileno (), sys .stderr .fileno ())
1043
- os .execv (cmd [0 ], cmd )
1023
+ else :
1024
+ preexec = None
1025
+
1026
+ # pylint: disable=subprocess-popen-preexec-fn
1027
+ return subprocess .Popen (cmd , stderr = subprocess .DEVNULL , preexec_fn = preexec )
1028
+
1029
+ def _spawn_chrome (self , cmd ):
1030
+ proc = self ._chrome_without_limit (cmd )
1031
+ pid = proc .pid
1032
+ port_file = pathlib .Path (self .user_data_dir , 'DevToolsActivePort' )
1033
+ for _ in range (100 ):
1034
+ time .sleep (0.1 )
1035
+ if port_file .is_file () and port_file .stat ().st_size > 5 :
1036
+ with port_file .open ('r' , encoding = 'utf-8' ) as f :
1037
+ self .devtools_port = int (f .readline ())
1038
+ break
1039
+ else :
1040
+ raise unittest .SkipTest ('Failed to detect chrome devtools port after 2.5s.' )
1041
+ return pid
1042
+
1044
1043
1045
1044
def _chrome_start (self ):
1046
1045
if self .chrome_pid is not None :
0 commit comments