fix: use process_group Popen argument with Python 3.11

This commit is contained in:
link2xt
2023-10-06 19:40:26 +00:00
parent 425a2310fe
commit f984a27379

View File

@@ -2,6 +2,7 @@ import json
import logging import logging
import os import os
import subprocess import subprocess
import sys
from queue import Queue from queue import Queue
from threading import Event, Thread from threading import Event, Thread
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
@@ -35,14 +36,22 @@ class Rpc:
self.events_thread: Thread self.events_thread: Thread
def start(self) -> None: def start(self) -> None:
if sys.version_info >= (3, 11):
self.process = subprocess.Popen( self.process = subprocess.Popen(
"deltachat-rpc-server", "deltachat-rpc-server",
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
# Prevent subprocess from capturing SIGINT. # Prevent subprocess from capturing SIGINT.
# We are not using `process_group` process_group=0,
# because it is not supported before Python 3.11. **self._kwargs,
preexec_fn=os.setpgrp, )
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._kwargs,
) )
self.id = 0 self.id = 0