Skip to content

Commit

Permalink
fix: try to fix terminal ui output on Linux (#134)
Browse files Browse the repository at this point in the history
Fix for terminal UI on Linux.
  • Loading branch information
jug-dev authored Mar 26, 2023
1 parent 63cac03 commit d73a868
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions worker/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import locale
import os
import re
import sys
import textwrap
import threading
import time
Expand All @@ -15,7 +16,7 @@
import psutil
import requests
import yaml
from loguru import logger
from nataili.util.logger import config, logger
from pynvml.smi import nvidia_smi


Expand Down Expand Up @@ -222,10 +223,19 @@ def __init__(self, worker_name=None, apikey=None, url="https://stablehorde.net")
self.last_audio_alert = 0

def initialise(self):
# Suppress stdout / stderr
sys.stderr = os.devnull
sys.stdout = os.devnull
if self.use_log_file:
self.open_log()
else:
# Hook loguru output
# Remove all loguru sinks
logger.remove()
handlers = [sink for sink in config["handlers"] if type(sink["sink"]) is str]
# Re-initialise loguru
newconfig = {"handlers": handlers}
logger.configure(**newconfig)
# Add our own handler
logger.add(self.input, level="DEBUG")
locale.setlocale(locale.LC_ALL, "")
self.initialise_main_window()
Expand Down Expand Up @@ -776,9 +786,9 @@ def run(self):
# Grab worker name and apikey if available
if os.path.isfile("bridgeData.yaml"):
with open("bridgeData.yaml", "rt", encoding="utf-8", errors="ignore") as configfile:
config = yaml.safe_load(configfile)
workername = config.get("worker_name", "")
apikey = config.get("api_key", "")
configdata = yaml.safe_load(configfile)
workername = configdata.get("worker_name", "")
apikey = configdata.get("api_key", "")

term = TerminalUI(workername, apikey)
# Standalone UI we need to inspect the log file
Expand Down

0 comments on commit d73a868

Please sign in to comment.