我有以下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
命令后),rospy.is_shutdown()
)和不知怎的,我正在努力识别ROS关闭,即使我尝试rospy.on_shutdown()
,也可以尝试自己的while
循环调用httpd.handle_request()
。
使用当前版本,关闭rosrun
时,节点(以roscore
开头)不会停止。
如何合理地合并这两个模块?
答案 0 :(得分:1)
我相信你可以通过在(或你自己的调用它的函数)上注册套接字关闭函数作为一个rospy关闭处理程序来停止。
def shutdown_hook():
print "Trying to shut down server"
httpd.shutdown()
rospy.on_shutdown(shutdown_hook)
如果shutdown()
不起作用,请尝试httpd.socket.close()