Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
baf69345
Commit
baf69345
authored
Nov 25, 2019
by
Eric Cousineau
Committed by
Wenzel Jakob
Nov 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor modifications to interrupt handling FAQ (#2007)
parent
0f1d3bfe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
12 deletions
+4
-12
docs/faq.rst
+4
-12
No files found.
docs/faq.rst
View file @
baf69345
...
@@ -257,30 +257,22 @@ is released, so a long-running function won't be interrupted.
...
@@ -257,30 +257,22 @@ is released, so a long-running function won't be interrupted.
To interrupt from inside your function, you can use the ``PyErr_CheckSignals()``
To interrupt from inside your function, you can use the ``PyErr_CheckSignals()``
function, that will tell if a signal has been raised on the Python side. This
function, that will tell if a signal has been raised on the Python side. This
function merely checks a flag, so its impact is negligible. When a signal has
function merely checks a flag, so its impact is negligible. When a signal has
been received, you
can explicitely interrupt execution by throwing an exception
been received, you
must either explicitly interrupt execution by throwing
that gets translated to KeyboardInterrupt (see :doc:`advanced/exceptions`
``py::error_already_set`` (which will propagate the existing
section
):
``KeyboardInterrupt``), or clear the error (which you usually will not want
):
.. code-block:: cpp
.. code-block:: cpp
class interruption_error: public std::exception {
public:
const char* what() const noexcept {
return "Interruption signal caught.";
}
};
PYBIND11_MODULE(example, m)
PYBIND11_MODULE(example, m)
{
{
m.def("long running_func", []()
m.def("long running_func", []()
{
{
for (;;) {
for (;;) {
if (PyErr_CheckSignals() != 0)
if (PyErr_CheckSignals() != 0)
throw
interruption_error
();
throw
py::error_already_set
();
// Long running iteration
// Long running iteration
}
}
});
});
py::register_exception<interruption_error>(m, "KeyboardInterrupt");
}
}
Inconsistent detection of Python version in CMake and pybind11
Inconsistent detection of Python version in CMake and pybind11
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment