File tree Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 6
6
without blocking any user interaction.
7
7
"""
8
8
import time
9
+ import asyncio
9
10
10
11
from prompt_toolkit import PromptSession
11
12
from prompt_toolkit .history import History , ThreadedHistory
@@ -32,11 +33,22 @@ def main():
32
33
"Even when the input is accepted, loading will continue in the "
33
34
"background and when the next prompt is displayed.\n "
34
35
)
35
- our_history = ThreadedHistory (SlowHistory ())
36
+
37
+ my_loop = asyncio .get_event_loop () # creates loop if needed
38
+
39
+ # Inform ThreadedHistory which event loop to use
40
+ # when passing lines of history to the prompt.
41
+
42
+ our_history = ThreadedHistory (SlowHistory (), my_loop )
36
43
37
44
# The history needs to be passed to the `PromptSession`. It can't be passed
38
45
# to the `prompt` call because only one history can be used during a
39
46
# session.
47
+ # Note that PromptSession runs on the thread's current event loop because
48
+ # it was created above and is therefore in synch with ThreadedHistory.
49
+ # PromptSession would create and event loop if it didn't find one
50
+ # already running, but then ThreadedHistory would not work.
51
+
40
52
session = PromptSession (history = our_history )
41
53
42
54
while True :
Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ class ThreadedHistory(History):
103
103
"""
104
104
105
105
def __init__ (
106
- self , history : History , event_loop : asyncio .BaseEventLoop = None
106
+ self , history : History , event_loop : Optional [ asyncio .BaseEventLoop ] = None
107
107
) -> None :
108
108
"""Create instance of ThreadedHistory
109
109
Original file line number Diff line number Diff line change @@ -556,8 +556,7 @@ def display_placeholder() -> bool:
556
556
# Users can insert processors here.
557
557
DynamicProcessor (lambda : merge_processors (self .input_processors or [])),
558
558
ConditionalProcessor (
559
- AfterInput (lambda : self .placeholder ),
560
- filter = display_placeholder ,
559
+ AfterInput (lambda : self .placeholder ), filter = display_placeholder ,
561
560
),
562
561
]
563
562
You can’t perform that action at this time.
0 commit comments