Skip to content

Commit

Permalink
Handle TimeoutExpired exception in process termination
Browse files Browse the repository at this point in the history
Added exception handling for TimeoutExpired when terminating signal-cli to ensure the process pipes are properly managed. The version number is incremented to 0.5.8.2 to reflect this improvement.
  • Loading branch information
pnearing committed Sep 9, 2024
1 parent 9d76c8d commit 265fb5f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "SignalCliAPi"
version = "0.5.8.1"
version = "0.5.8.2"
authors = [
{ name="Peter Nearing", email="[email protected]" }
]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = SignalCliApi
version = 0.5.8.1
version = 0.5.8.2
author = Peter Nearing
author_email = [email protected]
description = A python interface to the signal-cli found at https://github.com/AsamK/signal-cli
Expand Down
2 changes: 1 addition & 1 deletion src/signal_cli_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
File: __init__.py
Description: A python3 interface to signal-cli.
"""
__version__: str = '0.5.8.1'
__version__: str = '0.5.8.2'
__author__: str = 'Peter Nearing'
__email__: str = '[email protected]'

Expand Down
11 changes: 7 additions & 4 deletions src/signal_cli_api/signal_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import os
import socket
from subprocess import Popen, PIPE, CalledProcessError, check_output, check_call
from subprocess import Popen, PIPE, CalledProcessError, check_output, check_call, TimeoutExpired
from time import sleep
from typing import Optional, Callable, Any, NoReturn

Expand Down Expand Up @@ -457,9 +457,12 @@ def stop_signal(self) -> None:
__run_callback__(self._callback, "stopping signal-cli")
self._signal_process.terminate() # Kill the process (Sends SigTerm)
logger.debug("Flushing pipes.")
stdout, stderr = self._signal_process.communicate(timeout=1.0) # Flush the pipes.
logger.debug("STDOUT: %s", str(stdout))
logger.debug("STDERR: %s", str(stderr))
try:
stdout, stderr = self._signal_process.communicate(timeout=1.0) # Flush the pipes.
logger.debug("STDOUT: %s", str(stdout))
logger.debug("STDERR: %s", str(stderr))
except TimeoutExpired:
pass
self._signal_process = None # Clear the process.
logger.info("signal-cli stopped.")
__run_callback__(self._callback, "signal-cli stopped")
Expand Down

0 comments on commit 265fb5f

Please sign in to comment.