Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Robomaster_pi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Emil Harlan
Robomaster_pi
Commits
7573ccc2
Commit
7573ccc2
authored
1 year ago
by
Emil Harlan
Browse files
Options
Downloads
Patches
Plain Diff
a
parent
75997f0c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
robomaster_pi/command_executer.py
+7
-9
7 additions, 9 deletions
robomaster_pi/command_executer.py
with
7 additions
and
9 deletions
robomaster_pi/command_executer.py
+
7
−
9
View file @
7573ccc2
...
...
@@ -9,21 +9,19 @@ class CommandExecutor(Node):
super
().
__init__
(
'
command_executor
'
)
self
.
subscription
=
self
.
create_subscription
(
String
,
'
execute_command
'
,
'
launch_node
'
,
self
.
execute_command_callback
,
10
)
self
.
running_processes
=
{}
# Dictionary to store the running processes with custom names
def
execute_command_callback
(
self
,
msg
):
command
=
msg
.
data
.
split
()
# Split the received string into command and name
if
command
[
0
]
==
"
kill
"
:
self
.
kill_node
(
command
[
1
]
)
# Call the kill_node method using 'self'
name
,
command
=
msg
.
data
.
split
(
"
"
,
1
)
# Split the received string into command and name
if
command
==
"
kill
"
:
self
.
kill_node
(
command
)
# Call the kill_node method using 'self'
else
:
name
=
command
[
0
]
launch_command
=
"
"
.
join
(
command
[
1
:])
# Execute the launch command in a separate thread
threading
.
Thread
(
target
=
self
.
execute_command
,
args
=
(
name
,
launch_
command
)).
start
()
threading
.
Thread
(
target
=
self
.
execute_command
,
args
=
(
name
,
command
)).
start
()
def
execute_command
(
self
,
name
,
launch_command
):
try
:
...
...
@@ -40,8 +38,8 @@ class CommandExecutor(Node):
if
name
in
self
.
running_processes
:
try
:
process_handle
=
self
.
running_processes
[
name
]
process_handle
.
terminate
(
)
process_handle
.
wait
(
timeout
=
1
)
process_handle
.
send_signal
(
SIGINT
)
process_handle
.
wait
(
timeout
=
30
)
except
subprocess
.
TimeoutExpired
:
process_handle
.
kill
()
process_handle
.
wait
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment