You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the python wrapper for lcm_handle_timeout:
static PyObject *pylcm_handle_timeout(PyLCMObject *lcm_obj, PyObject *arg)
{
int timeout_millis = PyInt_AsLong(arg);
if (timeout_millis == -1 && PyErr_Occurred())
returnNULL;
if (timeout_millis < 0) {
PyErr_SetString(PyExc_ValueError, "invalid timeout");
returnNULL;
}
dbg(DBG_PYTHON, "pylcm_handle_timeout(%p, %d)\n", lcm_obj, timeout_millis);
if (lcm_obj->saved_thread_state) {
PyErr_SetString(PyExc_RuntimeError,
"Simultaneous calls to handle() / handle_timeout() detected");
returnNULL;
}
lcm_obj->saved_thread_state = PyEval_SaveThread();
lcm_obj->exception_raised = 0;
dbg(DBG_PYTHON, "calling lcm_handle_timeout(%p, %d)\n", lcm_obj->lcm, timeout_millis);
int status = lcm_handle_timeout(lcm_obj->lcm, timeout_millis);
// Restore the thread state before returning back to Python. The thread// state may have already been restored by the callback function// pylcm_msg_handler()if (lcm_obj->saved_thread_state) {
PyEval_RestoreThread(lcm_obj->saved_thread_state);
lcm_obj->saved_thread_state = NULL;
}
if (lcm_obj->exception_raised) {
returnNULL;
}
if (status < 0) {
PyErr_SetString(PyExc_IOError, "lcm_handle_timeout() returned -1");
returnNULL;
}
returnPyInt_FromLong(status);
}
And this is the C++ wrapper:
inlineintLCM::handleTimeout(int timeout_millis)
{
if (!this->lcm) {
fprintf(stderr, "LCM instance not initialized. Ignoring call to handle()\n");
return -1;
}
returnlcm_handle_timeout(this->lcm, timeout_millis);
}
Note, the latter simply returns whatever lcm_handle_timeout, but the python implementation throws an IOError if status < 0.
I think the C++ implementation makes more sense, as it should be up to the user to decide what to do with the retval of lcm_handle_timeout. For example, when playing a log file, this function returns -1 at the end of the file. This isn't really worth throwing an exception when we can just return -1.
Should change the python wrapper to match the C++ wrapper. Likely would impact #201.
The text was updated successfully, but these errors were encountered:
This is the python wrapper for
lcm_handle_timeout
:And this is the C++ wrapper:
Note, the latter simply returns whatever
lcm_handle_timeout
, but the python implementation throws anIOError
ifstatus < 0
.I think the C++ implementation makes more sense, as it should be up to the user to decide what to do with the retval of
lcm_handle_timeout
. For example, when playing a log file, this function returns -1 at the end of the file. This isn't really worth throwing an exception when we can just return -1.Should change the python wrapper to match the C++ wrapper. Likely would impact #201.
The text was updated successfully, but these errors were encountered: