Skip to content

Commit a477bd8

Browse files
committed
Add loop_factory kwarg to bg_loop.threaded_loop
resolves #22
1 parent b002be8 commit a477bd8

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/async_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__author__ = "Michael Hall"
1010
__license__ = "Apache-2.0"
1111
__copyright__ = "Copyright 2020-Present Michael Hall"
12-
__version__ = "2025.06.08b"
12+
__version__ = "2025.06.25b"
1313

1414
import os
1515
import sys

src/async_utils/bg_loop.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import asyncio
2020
import concurrent.futures as cf
2121
import threading
22-
from collections.abc import Coroutine, Generator
22+
from collections.abc import Callable, Coroutine, Generator
2323
from contextlib import contextmanager
2424

2525
from . import _typings as t
@@ -139,7 +139,10 @@ def _run_forever(
139139

140140
@contextmanager
141141
def threaded_loop(
142-
*, use_eager_task_factory: bool = True, wait_on_exit: bool = True
142+
*,
143+
use_eager_task_factory: bool = True,
144+
wait_on_exit: bool = True,
145+
loop_factory: Callable[[], asyncio.AbstractEventLoop] | None = None,
143146
) -> Generator[LoopWrapper, None, None]:
144147
"""Create and use a managed event loop in a backround thread.
145148
@@ -157,7 +160,7 @@ def threaded_loop(
157160
LoopWrapper
158161
A wrapper with methods for interacting with the background loop.
159162
"""
160-
loop = asyncio.new_event_loop()
163+
loop = (loop_factory or asyncio.new_event_loop)()
161164
thread = None
162165
wrapper = None
163166
try:

0 commit comments

Comments
 (0)