Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register our signal handler in rclpy_init vs each wait #194

Merged
merged 3 commits into from
Jun 24, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions rclpy/src/rclpy/_rclpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ rclpy_init(PyObject * Py_UNUSED(self), PyObject * args)
}
Py_DECREF(pyargs);

// Register our signal handler that will forward to the original one.
g_original_signal_handler = signal(SIGINT, catch_function);

if (PyErr_Occurred()) {
return NULL;
}
Expand Down Expand Up @@ -2345,7 +2348,6 @@ rclpy_wait(PyObject * Py_UNUSED(self), PyObject * args)
if (!PyArg_ParseTuple(args, "O|K", &pywait_set, &timeout)) {
return NULL;
}
g_original_signal_handler = signal(SIGINT, catch_function);
rcl_wait_set_t * wait_set = (rcl_wait_set_t *)PyCapsule_GetPointer(pywait_set, "rcl_wait_set_t");
if (!wait_set) {
return NULL;
Expand All @@ -2357,8 +2359,6 @@ rclpy_wait(PyObject * Py_UNUSED(self), PyObject * args)
ret = rcl_wait(wait_set, timeout);
Py_END_ALLOW_THREADS;

signal(SIGINT, g_original_signal_handler);
g_original_signal_handler = NULL;
if (ret != RCL_RET_OK && ret != RCL_RET_TIMEOUT) {
PyErr_Format(PyExc_RuntimeError,
"Failed to wait on wait set: %s", rcl_get_error_string_safe());
Expand Down Expand Up @@ -2659,6 +2659,11 @@ rclpy_shutdown(PyObject * Py_UNUSED(self), PyObject * Py_UNUSED(args))
rcl_reset_error();
return NULL;
}

// Restore the original signal handler.
signal(SIGINT, g_original_signal_handler);
g_original_signal_handler = NULL;

Py_RETURN_NONE;
}

Expand Down