This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Any | |
from collections import deque | |
from collections.abc import Generator | |
def multiplex_generators( | |
*generators: Generator[Any, Any, Any], | |
) -> Generator[Any, Any, Any]: | |
"""Run multiple generators 'concurrently', yielding their results as they come.""" | |
active_generators = deque(generators) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json as std_json | |
from typing import TYPE_CHECKING, Any | |
import orjson | |
# Mapping json kwargs to orjson options | |
JSON_TO_ORJSON_OPTIONS = { | |
"indent": orjson.OPT_INDENT_2, # maps indent to OPT_INDENT_2 (note: no control over indent size) | |
"sort_keys": orjson.OPT_SORT_KEYS, | |
"default": "default", # handle separately |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
import atexit | |
from multiprocessing.pool import ThreadPool | |
from pathlib import Path | |
from typing import TYPE_CHECKING | |
import cv2 | |
import numpy as np | |
from PIL import Image |