CommonClient: move to explicit thread instead of thread executor to allow proper task cancelling.
This commit is contained in:
parent
5e84900ac4
commit
d768379a8a
|
@ -540,14 +540,26 @@ async def process_server_cmd(ctx: CommonContext, args: dict):
|
|||
ctx.on_package(cmd, args)
|
||||
|
||||
|
||||
def stream_input(stream, queue):
|
||||
def queuer():
|
||||
text = stream.readline().strip()
|
||||
if text:
|
||||
queue.put_nowait(text)
|
||||
|
||||
from threading import Thread
|
||||
thread = Thread(target=queuer, name=f"Stream handler for {stream.name}", daemon=True)
|
||||
thread.start()
|
||||
return thread
|
||||
|
||||
|
||||
async def console_loop(ctx: CommonContext):
|
||||
import sys
|
||||
commandprocessor = ctx.command_processor(ctx)
|
||||
queue = asyncio.Queue()
|
||||
stream_input(sys.stdin, queue)
|
||||
while not ctx.exit_event.is_set():
|
||||
try:
|
||||
input_text = await asyncio.get_event_loop().run_in_executor(
|
||||
None, sys.stdin.readline
|
||||
)
|
||||
input_text = await queue.get()
|
||||
input_text = input_text.strip()
|
||||
|
||||
if ctx.input_requests > 0:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
colorama>=0.4.4
|
||||
websockets>=10.0
|
||||
websockets>=10.1
|
||||
PyYAML>=6.0
|
||||
fuzzywuzzy>=0.18.0
|
||||
prompt_toolkit>=3.0.22
|
||||
prompt_toolkit>=3.0.23
|
||||
appdirs>=1.4.4
|
||||
jinja2>=3.0.3
|
||||
schema>=0.7.4
|
||||
|
|
Loading…
Reference in New Issue