Skip to content

Commit

Permalink
Clients: fix high CPU usage when launched via MultiProcessing (#4209)
Browse files Browse the repository at this point in the history
* Core: make Utils.stream_input not consume all CPU for non-blocking streams

* Clients: ignore MultiProcessing pipe as input console
  • Loading branch information
black-sliver authored Nov 18, 2024
1 parent 01c6037 commit 3ae8992
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CommonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,11 @@ def run_gui(self):

def run_cli(self):
if sys.stdin:
if sys.stdin.fileno() != 0:
from multiprocessing import parent_process
if parent_process():
return # ignore MultiProcessing pipe

# steam overlay breaks when starting console_loop
if 'gameoverlayrenderer' in os.environ.get('LD_PRELOAD', ''):
logger.info("Skipping terminal input, due to conflicting Steam Overlay detected. Please use GUI only.")
Expand Down
3 changes: 3 additions & 0 deletions Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from argparse import Namespace
from settings import Settings, get_settings
from time import sleep
from typing import BinaryIO, Coroutine, Optional, Set, Dict, Any, Union
from typing_extensions import TypeGuard
from yaml import load, load_all, dump
Expand Down Expand Up @@ -568,6 +569,8 @@ def queuer():
else:
if text:
queue.put_nowait(text)
else:
sleep(0.01) # non-blocking stream

from threading import Thread
thread = Thread(target=queuer, name=f"Stream handler for {stream.name}", daemon=True)
Expand Down

0 comments on commit 3ae8992

Please sign in to comment.