Skip to content

Commit f3e1c25

Browse files
committed
[FIX] tests: avoid to fork in multithread process
Since python 3.12 python/cpython#100229, fork inside a multithreaded process will raise a warning. We actually have another solution to get rid of the fork that was implemented in more recent versions.
1 parent 0b2b5ef commit f3e1c25

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

odoo/tests/common.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,35 +1012,34 @@ def executable(self):
10121012
self._logger.warning("Chrome executable not found")
10131013
raise unittest.SkipTest("Chrome executable not found")
10141014

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():
10381021
import resource
10391022
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+
10441043

10451044
def _chrome_start(self):
10461045
if self.chrome_pid is not None:

0 commit comments

Comments
 (0)