Ask Your Question
4

rospy: throttling logmessage rate?

asked 2013-10-24 07:57:16 -0600

gvdhoorn gravatar image

updated 2015-06-24 09:51:21 -0600

In roscpp we can use the ROS_*_THROTTLE(..) macros, but rospy doesn't seem to have anything like that.

Any suggestions as to what would be the most elegant / pythonic way of achieving something equivalent in rospy?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2015-06-24 09:51:41 -0600

gvdhoorn gravatar image

updated 2016-06-03 14:06:30 -0600

Update (2016-06-03): a recent PR added support for throttled logging in Python. See wiki/rospy/Overview/Logging - Logging Periodically.


Answering my own question:

It would seem this is rather difficult to implement in Python. The ROS_*_THROTTLE(..) macro can exploit some features of C/C++ (variable scoping, static variables): state information is inserted for every individual invocation of the macro (see ros/console.h#L422-433). This makes it possible to easily support multiple calls with different period arguments, without resorting to for instance __FILE__ __LINE__ trickery (which wouldn't work anyway).

Python does not support this, and would require a different approach. After some experimentation, adding runtime, per-invocation state information seems hard to implement, at least in a way supported by the many runtimes in existence and/or Python 3+. One approach could be to use a (object_id, function_name, line_nr) tuple to uniquely identify an invocation. Unfortunately it seems impossible to retrieve this information without the use of functionality not supported everywhere (inspect and / or sys._getframe()). This would also shift the responsibility of keeping track of previous invocations to the log*throttle(..) implementations.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

4 followers

Stats

Asked: 2013-10-24 07:57:16 -0600

Seen: 1,357 times

Last updated: Jun 03 '16