feat: 正确终止服务器(疑似)
This commit is contained in:
parent
2ce41b8372
commit
81eed99a03
@ -95,7 +95,7 @@ class GazeboSimHttpServer(HttpRPCServer):
|
||||
# 启动roscore
|
||||
self.roscore_proc = subprocess.Popen(
|
||||
['roscore'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
time.sleep(2)
|
||||
time.sleep(5)
|
||||
rospy.init_node('gazebo_world_manager', anonymous=True)
|
||||
|
||||
# 添加接口
|
||||
@ -259,6 +259,22 @@ class GazeboSimHttpServer(HttpRPCServer):
|
||||
print('Server remove model done.')
|
||||
return jsonify(ret)
|
||||
|
||||
def shutdown(self):
|
||||
"""
|
||||
关闭所有资源。
|
||||
"""
|
||||
# 1. 关闭场景(如果正在运行)
|
||||
if self.scene_mgr.running_scene:
|
||||
self.shut_scene()
|
||||
# 2. 关闭 HeartbeatServer
|
||||
self.heartbeat_server.stop()
|
||||
# 3. 关闭 roscore 进程
|
||||
if self.roscore_proc:
|
||||
self.roscore_proc.terminate()
|
||||
self.roscore_proc.wait()
|
||||
# 4. 关闭 Flask HTTP 服务器
|
||||
super().stop()
|
||||
print("GazeboSimHttpServer stopped.")
|
||||
|
||||
if __name__ == '__main__':
|
||||
server = GazeboSimHttpServer()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user