Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
- CLI tests
- `NavaThread._terminate_process` method
### Changed
- Python typing features added to all modules
- CLI functions moved to `cli.py`
- `NavaThread.stop` method updated
- Dependencies structure modified
- Test system modified
## [0.8] - 2025-12-17
Expand Down
45 changes: 22 additions & 23 deletions nava/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ def __init__(self, loop: bool, engine: Engine, *args: List[Any], **kwargs: Dict[
self._engine = engine
self._nava_exception = None

def _terminate_process(self) -> None:
"""Terminate play process and clean up its standard streams."""
try:
self._play_process.stdout.close()
self._play_process.stdin.close()
self._play_process.stderr.close()
except Exception: # nosec B110 - Best effort cleanup
pass

try:
self._play_process.terminate()
self._play_process.wait(timeout=1)
except Exception:
try:
self._play_process.kill()
self._play_process.wait()
except Exception: # nosec B110 - Best effort cleanup
pass
finally:
self._play_process = None

def run(self) -> None:
"""Run target function."""
try:
Expand Down Expand Up @@ -54,26 +75,4 @@ def stop(self) -> None:
# So the main thread can't "see" the alias created in the worker thread.
else:
if self._play_process:
# Best-effort: close all standard streams
try:
self._play_process.stdout.close()
self._play_process.stdin.close()
self._play_process.stderr.close()
except Exception: # nosec B110 - Best effort cleanup, ignore all errors
# Streams may be None, already closed, or OS-specific issues
pass

# Try graceful termination
try:
self._play_process.terminate()
self._play_process.wait(timeout=1)
except Exception:
# Fallback to force kill - catch any process-related errors
try:
self._play_process.kill()
self._play_process.wait()
except Exception: # nosec B110 - Best effort cleanup, ignore all errors
# Process already terminated or any other issues
pass
finally:
self._play_process = None
self._terminate_process()
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Setup module."""
from setuptools import setup


def read_description() -> str:
"""Read README.md and CHANGELOG.md."""
try:
Expand Down
Loading