Skip to content

Commit

Permalink
discovery_client: Fix auto-launching discovery service producing a Re…
Browse files Browse the repository at this point in the history
…sourceWarning (#344)

* discovery_client: Get rid of resource warning

* Ran black

* discovery_client: Fix comments and private variable for subprocess
  • Loading branch information
Vikram S A authored Aug 1, 2023
1 parent c89b733 commit 3e0ded3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ni_measurementlink_service/_internal/discovery_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import winerror

_logger = logging.getLogger(__name__)
# Save Popen object to avoid "ResourceWarning: subprocess N is still running"
_discovery_service_subprocess: Optional[subprocess.Popen] = None

_START_SERVICE_TIMEOUT = 30.0
_START_SERVICE_POLLING_INTERVAL = 100e-3
Expand Down Expand Up @@ -257,7 +259,8 @@ def _key_file_exists(key_file_path: pathlib.Path) -> bool:

def _start_service(exe_file_path: pathlib.PurePath, key_file_path: pathlib.Path) -> None:
"""Starts the service at the specified path and wait for the service to get up and running."""
subprocess.Popen(
global _discovery_service_subprocess # save Popen object to avoid ResourceWarning
_discovery_service_subprocess = subprocess.Popen(
[exe_file_path],
cwd=exe_file_path.parent,
stdout=subprocess.DEVNULL,
Expand Down

0 comments on commit 3e0ded3

Please sign in to comment.