From f984a273793525ca6e86328af9ac075c97aba729 Mon Sep 17 00:00:00 2001 From: link2xt Date: Fri, 6 Oct 2023 19:40:26 +0000 Subject: [PATCH] fix: use process_group Popen argument with Python 3.11 --- .../src/deltachat_rpc_client/rpc.py | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py b/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py index 506a01a66..65b1391dc 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py @@ -2,6 +2,7 @@ import json import logging import os import subprocess +import sys from queue import Queue from threading import Event, Thread from typing import Any, Dict, Optional @@ -35,16 +36,24 @@ class Rpc: self.events_thread: Thread def start(self) -> None: - self.process = subprocess.Popen( - "deltachat-rpc-server", - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - # Prevent subprocess from capturing SIGINT. - # We are not using `process_group` - # because it is not supported before Python 3.11. - preexec_fn=os.setpgrp, - **self._kwargs, - ) + if sys.version_info >= (3, 11): + self.process = subprocess.Popen( + "deltachat-rpc-server", + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + # Prevent subprocess from capturing SIGINT. + process_group=0, + **self._kwargs, + ) + else: + self.process = subprocess.Popen( + "deltachat-rpc-server", + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + # `process_group` is not supported before Python 3.11. + preexec_fn=os.setpgrp, # noqa: PLW1509 + **self._kwargs, + ) self.id = 0 self.event_queues = {} self.request_events = {}