mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Support for older python
This commit is contained in:
parent
19c272633d
commit
e34681b159
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user