-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #317 from hello-robot/feature/multiuser_multirobot…
…process_protection Robot process protection for multi-user setup
- Loading branch information
Showing
7 changed files
with
102 additions
and
53 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
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 |
---|---|---|
@@ -1,23 +1,8 @@ | ||
#!/usr/bin/env python3 | ||
import os | ||
import signal | ||
import time | ||
from filelock import FileLock, Timeout | ||
from stretch_body.hello_utils import free_body_filelock | ||
|
||
pid_file = "/tmp/stretch_body_robot_pid.txt" | ||
file_lock = FileLock(f"{pid_file}.lock") | ||
try: | ||
file_lock.acquire(timeout=1) | ||
file_lock.release() | ||
except Timeout: | ||
with open(pid_file, 'r') as f: | ||
tokill_pid = int(f.read()) | ||
# send SIGTERM a few times some processes (e.g. ipython) | ||
# try to stall on exit | ||
os.kill(tokill_pid, signal.SIGTERM) | ||
time.sleep(0.2) | ||
os.kill(tokill_pid, signal.SIGTERM) | ||
time.sleep(0.2) | ||
os.kill(tokill_pid, signal.SIGTERM) | ||
finally: | ||
did_free = free_body_filelock() | ||
if did_free: | ||
print('Done!') | ||
else: | ||
print('Failed because robot is being used by another user. To force kill the process, try running "sudo -E env PATH=$PATH stretch_free_robot_process.py"') |
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
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