Support for older python

This commit is contained in:
Kovid Goyal 2025-04-06 13:38:01 +05:30
parent 19c272633d
commit e34681b159
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -9,12 +9,20 @@ import ssl
import traceback
from collections.abc import Callable, Iterator
from contextlib import ExitStack
from itertools import batched, chain
from itertools import chain, islice
from typing import Any, BinaryIO, NamedTuple, TypeVar
T = TypeVar('T')
R = TypeVar('R')
try:
from itertools import batched
except ImportError:
def batched(iterable, n):
iterator = iter(iterable)
while batch := tuple(islice(iterator, n)):
yield batch
class _RemoteTraceback(Exception):
def __init__(self, tb):
@ -60,7 +68,9 @@ class Worker:
return self
def __exit__(self, exc_type, exc_value, tb) -> None:
try:
self.pipe.close()
finally:
pid, status = os.waitpid(self.pid, os.WNOHANG)
if not pid:
os.kill(self.pid, signal.SIGKILL)