-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ROSLaunchController for controlling ROS launch processes (fixes #354
) (#359) * added ROSLaunchController class * added terminate method * added filename to controller * added command attribute * added close method * added pid property * added ROSLaunchController to launch method * added __enter__ and __exit__ methods * added is_running method * added missing import * updated CHANGELOG * Added missing `not` Co-authored-by: afsafzal <afsoona@cs.cmu.edu> * mark running as property Co-authored-by: afsafzal <afsoona@cs.cmu.edu>
- Loading branch information
1 parent
c001dfc
commit 791bc6a
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,54 @@ | ||
# -*- coding: utf-8 -*- | ||
__all__ = ('ROSLaunchController',) | ||
|
||
from types import TracebackType | ||
from typing import Iterator, Optional, Type | ||
|
||
import attr | ||
import dockerblade | ||
|
||
|
||
@attr.s(frozen=True, slots=True, auto_attribs=True) | ||
class ROSLaunchController: | ||
"""Provides an interface to a roslaunch process. | ||
Attributes | ||
---------- | ||
filename: str | ||
The absolute path of the XML launch file used by this process. | ||
command: str | ||
The command string that was used by this process. | ||
popen: dockerblade.popen.Popen | ||
An interface to the underlying exec process for this roslaunch process. | ||
pid: Optional[int] | ||
The PID of the launch process inside the container, if known. | ||
""" | ||
filename: str | ||
popen: dockerblade.popen.Popen = attr.ib(repr=False) | ||
|
||
def __enter__(self) -> 'ROSLaunchController': | ||
return self | ||
|
||
def __exit__(self, | ||
ex_type: Optional[Type[BaseException]], | ||
ex_val: Optional[BaseException], | ||
ex_tb: Optional[TracebackType] | ||
) -> None: | ||
self.close() | ||
|
||
@property | ||
def stream(self) -> Iterator[str]: | ||
yield from self.popen.stream() # type: ignore | ||
|
||
@property | ||
def running(self) -> bool: | ||
"""Checks whether or not this roslaunch process is still running.""" | ||
return not self.popen.finished | ||
|
||
def terminate(self) -> None: | ||
"""Terminates this roslaunch process.""" | ||
self.popen.terminate() | ||
|
||
def close(self) -> None: | ||
"""Terminates this roslaunch process.""" | ||
self.terminate() |
This file contains 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