simplify popen

This commit is contained in:
holger krekel
2025-11-23 20:53:49 +01:00
parent 8eef79f95d
commit 4188c2e4f5

View File

@@ -79,24 +79,16 @@ class Rpc:
def start(self) -> None: def start(self) -> None:
"""Start RPC server subprocess.""" """Start RPC server subprocess."""
popen_kwargs = {"stdin": subprocess.PIPE, "stdout": subprocess.PIPE}
if sys.version_info >= (3, 11): if sys.version_info >= (3, 11):
self.process = subprocess.Popen( # Prevent subprocess from capturing SIGINT.
"deltachat-rpc-server", popen_kwargs["process_group"] = 0
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
# Prevent subprocess from capturing SIGINT.
process_group=0,
**self._kwargs,
)
else: else:
self.process = subprocess.Popen( # `process_group` is not supported before Python 3.11.
"deltachat-rpc-server", popen_kwargs["preexec_fn"] = os.setpgrp # noqa: PLW1509
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, popen_kwargs.update(self._kwargs)
# `process_group` is not supported before Python 3.11. self.process = subprocess.Popen("deltachat-rpc-server", **popen_kwargs)
preexec_fn=os.setpgrp, # noqa: PLW1509
**self._kwargs,
)
self.id_iterator = itertools.count(start=1) self.id_iterator = itertools.count(start=1)
self.event_queues = {} self.event_queues = {}
self.request_results = {} self.request_results = {}