Skip to content

Commit

Permalink
feat(shell): add timeout warning and faster update
Browse files Browse the repository at this point in the history
see #990
  • Loading branch information
tobi-wan-kenobi committed Sep 15, 2023
1 parent d303b79 commit 2e7e75a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bumblebee_status/modules/contrib/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def update(self):
# if requested then run not async version and just execute command in this thread
if not self.__async:
self.__output = util.cli.execute(self.__command, shell=True, ignore_errors=True).strip()
core.event.trigger("update", [self.id], redraw_only=True)
return

# if previous thread didn't end yet then don't do anything
Expand All @@ -71,6 +72,7 @@ def update(self):
self.__current_thread = threading.Thread(
target=lambda obj, cmd: obj.set_output(
util.cli.execute(cmd, ignore_errors=True)
core.event.trigger("update", [self.id], redraw_only=True)
),
args=(self, self.__command),
)
Expand Down
14 changes: 13 additions & 1 deletion bumblebee_status/util/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,19 @@ def execute(
raise RuntimeError("{} not found".format(cmd))

if wait:
out, _ = proc.communicate()
timeout = 60
try:
out, _ = proc.communicate(timeout=timeout)
except subprocess.TimeoutExpired as e:
logging.warning(
f"""
Communication with process pid={proc.pid} hangs for more
than {timeout} seconds.
If this is not expected, the process is stale, or
you might have run in stdout / stderr deadlock.
"""
)
out, _ = proc.communicate()
if proc.returncode != 0:
err = "{} exited with code {}".format(cmd, proc.returncode)
logging.warning(err)
Expand Down

0 comments on commit 2e7e75a

Please sign in to comment.