-
Notifications
You must be signed in to change notification settings - Fork 157
Wrapping LCM logger in Services #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b545ad0
logger node init
sarthakdas 6c881a5
logger node start service
sarthakdas edff9c0
stop logging service
sarthakdas cffd896
removal of chatter
sarthakdas ddcdef8
typing changes
sarthakdas dca1603
removal of extra imports
sarthakdas 63620a4
update to lcm_logger
sarthakdas 4b1be75
update log line
sarthakdas dab4b79
lcm docstring + killing change
sarthakdas 469e3c6
logging text change
sarthakdas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| from typing import Optional, Any | ||
|
|
||
| from ark.client.comm_infrastructure.base_node import BaseNode, main | ||
| from ark.tools.log import log | ||
| from arktypes import string_t, flag_t, status_t | ||
| import subprocess | ||
|
|
||
|
|
||
| class LoggerNode(BaseNode): | ||
|
|
||
| def __init__(self, name: str, config: Optional[dict[str, Any]] = None): | ||
| """ | ||
| @brief Construct the logger node and register services. | ||
|
|
||
| @param name Node name. | ||
| @param config Optional configuration dictionary (unused). | ||
| """ | ||
| super().__init__(name) | ||
| self.proc: Optional[subprocess.Popen] = None | ||
|
|
||
| self.create_service( | ||
| "logger/start", string_t, status_t, self.start_logging | ||
| ) | ||
| self.create_service( | ||
| "logger/stop", flag_t, status_t, self.stop_logging | ||
| ) | ||
|
|
||
| def start_logging(self, channel: str, msg: string_t) -> status_t: | ||
| """ | ||
| @brief Start an LCM logging session if none is running. | ||
|
|
||
| @param channel Service channel name (unused). | ||
| @param msg Output file prefix/path (`string_t.data`) for `lcm-logger`. | ||
|
|
||
| @return `status_t` | ||
| """ | ||
| out = status_t() | ||
|
|
||
| if self.proc is not None: | ||
| log.warning( | ||
| "lcm-logger already running; refusing to start a second session." | ||
| ) | ||
| out.success = False | ||
| out.message = "lcm-logger already running" | ||
| return out | ||
|
|
||
| try: | ||
| log.info("Started logging") | ||
| self.proc = subprocess.Popen( | ||
| ["lcm-logger", msg.data], | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| start_new_session=True, | ||
| ) | ||
| out.success = True | ||
| out.message = "lcm-logger started successfully" | ||
| except Exception as e: | ||
| log.error("Failed to start lcm-logger: %s", e) | ||
| self.proc = None | ||
| out.success = False | ||
| out.message = str(e) | ||
|
|
||
| return out | ||
|
|
||
| def stop_logging(self, channel: str, msg: flag_t) -> status_t: | ||
| """ | ||
| @brief Stop the current LCM logging session, if running. | ||
|
|
||
| @param channel Service channel name. | ||
| @param msg Input `flag_t` (unused). | ||
| """ | ||
| out = status_t() | ||
|
|
||
| if self.proc is None: | ||
| log.warning("No lcm-logger session is running.") | ||
| out.success = False | ||
| out.message = "No lcm-logger session is running." | ||
| return out | ||
|
|
||
| try: | ||
| self.proc.kill() | ||
| self.proc.wait(timeout=5) | ||
| log.info("Stopped logging") | ||
| del self.proc | ||
| self.proc = None | ||
| out.success = True | ||
| out.message = "lcm-logger stopped successfully" | ||
| except Exception as e: | ||
| log.error("Failed to stop lcm-logger: %s", e) | ||
| out.success = False | ||
| out.message = str(e) | ||
|
|
||
| return out | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main(LoggerNode, "Logger") | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont we need to call
del self.procto make sure the memory is cleared?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im not sure couldn't see a difference with/without including for safety?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea perhaps