8000 Fixed concurrency issue in generator_to_async_generator. · cool-RR/python-prompt-toolkit@ee18d1c · GitHub
[go: up one dir, main page]

Skip to content

Commit ee18d1c

Browse files
Fixed concurrency issue in generator_to_async_generator.
1 parent a7e7cc2 commit ee18d1c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

prompt_toolkit/eventloop/async_generator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Implementation for async generators.
33
"""
4-
from asyncio import Queue
4+
from asyncio import Queue, get_event_loop
55
from typing import AsyncGenerator, Callable, Iterable, TypeVar, Union
66

77
from .utils import run_in_executor_with_context
@@ -31,6 +31,7 @@ async def generator_to_async_generator(
3131
quitting = False
3232
_done = _Done()
3333
q: Queue[Union[_T, _Done]] = Queue()
34+
loop = get_event_loop()
3435

3536
def runner() -> None:
3637
"""
@@ -39,7 +40,7 @@ def runner() -> None:
3940
"""
4041
try:
4142
for item in get_iterable():
42-
q.put_nowait(item)
43+
loop.call_soon_threadsafe(q.put_nowait, item)
4344

4445
# When this async generator was cancelled (closed), stop this
4546
# thread.

0 commit comments

Comments
 (0)
0