Skip to content

Instantly share code, notes, and snippets.

View monkeytruffle's full-sized avatar

monkeytruffle

View GitHub Profile
@monkeytruffle
monkeytruffle / threaded_generator.py
Last active March 26, 2024 18:50
A class to iterate any iterable object in a new thread, plus a class to make this functionality available as a decorator for generator functions
import threading, queue, functools, logging
from collections.abc import Generator
from contextlib import closing
SENTINEL = StopIteration
logger = logging.getLogger(__name__)
class ThreadedGenerator(Generator, closing):
'''