Skip to content

Commit

Permalink
more aioconsole bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechromancer committed Feb 9, 2024
1 parent ae25d8a commit c151411
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions bbot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import traceback
from omegaconf import OmegaConf
from contextlib import suppress
from aioconsole.stream import NonFileStreamReader
from aioconsole import stream

# fix tee buffering
sys.stdout.reconfigure(line_buffering=True)
Expand Down Expand Up @@ -322,7 +322,13 @@ def handle_keyboard_input(keyboard_input):
toggle_log_level(logger=log)
scanner.manager.modules_status(_log=True)

reader = NonFileStreamReader(sys.stdin)
log.critical(f"is_pipe_transport_compatible: {stream.is_pipe_transport_compatible(sys.stdin)}")
reader = stream.NonFileStreamReader(sys.stdin)

# Reader
reader = stream.StandardStreamReader()
protocol = stream.StandardStreamReaderProtocol(reader)
await asyncio.get_event_loop().connect_read_pipe(lambda: protocol, sys.stdin)

async def akeyboard_listen():
try:
Expand All @@ -331,8 +337,10 @@ async def akeyboard_listen():
keyboard_input = None
try:
keyboard_input = smart_decode((await reader.readline()).strip())
allowed_errors = 0
except Exception:
allowed_errors = 10
except Exception as e:
log_to_stderr(f"Error in keyboard listen loop: {e}", level="TRACE")
log_to_stderr(traceback.format_exc(), level="TRACE")
allowed_errors -= 1
if keyboard_input is not None:
handle_keyboard_input(keyboard_input)
Expand Down

0 comments on commit c151411

Please sign in to comment.