当rospy.is_shutdown

时间:2015-08-24 07:34:42

标签: python shutdown ros simplehttpserver rospy

我有以下Python程序来启动HTTP服务器和ROS节点。

httpd = ThreadingHttpServer()

rospy.init_node('server')
rospy.on_shutdown(httpd.shutdown)

try:
    httpd.serve_forever()
except KeyboardInterrupt:
    pass

httpd.server_close()

我希望程序终止

  • 当我致电httpd.shutdown()时(例如,在收到/kill命令后),
  • 当ROS关闭时(即如果rospy.is_shutdown())和
  • 当我按 Ctrl + C 时(这是最不重要的)。

不知怎的,我正在努力识别ROS关闭,即使我尝试rospy.on_shutdown(),也可以尝试自己的while循环调用httpd.handle_request()

使用当前版本,关闭rosrun时,节点(以roscore开头)不会停止。

如何合理地合并这两个模块?

1 个答案:

答案 0 :(得分:1)

我相信你可以通过在(或你自己的调用它的函数)上注册套接字关闭函数作为一个rospy关闭处理程序来停止。

   def shutdown_hook():
       print "Trying to shut down server"
       httpd.shutdown()

   rospy.on_shutdown(shutdown_hook)

如果shutdown()不起作用,请尝试httpd.socket.close()