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
|
import traceback
|
||||||
from collections.abc import Callable, Iterator
|
from collections.abc import Callable, Iterator
|
||||||
from contextlib import ExitStack
|
from contextlib import ExitStack
|
||||||
from itertools import batched, chain
|
from itertools import chain, islice
|
||||||
from typing import Any, BinaryIO, NamedTuple, TypeVar
|
from typing import Any, BinaryIO, NamedTuple, TypeVar
|
||||||
|
|
||||||
T = TypeVar('T')
|
T = TypeVar('T')
|
||||||
R = TypeVar('R')
|
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):
|
class _RemoteTraceback(Exception):
|
||||||
def __init__(self, tb):
|
def __init__(self, tb):
|
||||||
@ -60,7 +68,9 @@ class Worker:
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, tb) -> None:
|
def __exit__(self, exc_type, exc_value, tb) -> None:
|
||||||
|
try:
|
||||||
self.pipe.close()
|
self.pipe.close()
|
||||||
|
finally:
|
||||||
pid, status = os.waitpid(self.pid, os.WNOHANG)
|
pid, status = os.waitpid(self.pid, os.WNOHANG)
|
||||||
if not pid:
|
if not pid:
|
||||||
os.kill(self.pid, signal.SIGKILL)
|
os.kill(self.pid, signal.SIGKILL)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user