aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/pybind11/docs/advanced/pycpp/utilities.rst
diff options
context:
space:
mode:
authormyrtle <gatecat@ds0.me>2022-09-15 09:06:35 +0200
committerGitHub <noreply@github.com>2022-09-15 09:06:35 +0200
commit3983d4fe53e2c609a5c76510aff8e998a4c22285 (patch)
tree1c4a543f661dd1b281aecf4660388491702fa8d8 /3rdparty/pybind11/docs/advanced/pycpp/utilities.rst
parentf1349e114f3a16ccd002e8513339e18f5be4d31b (diff)
parenta72f898ff4c4237424c468044a6db9d6953b541e (diff)
downloadnextpnr-3983d4fe53e2c609a5c76510aff8e998a4c22285.tar.gz
nextpnr-3983d4fe53e2c609a5c76510aff8e998a4c22285.tar.bz2
nextpnr-3983d4fe53e2c609a5c76510aff8e998a4c22285.zip
Merge pull request #1024 from YosysHQ/gatecat/pybind11-bump
3rdparty: Bump vendored pybind11 version for py3.11 support
Diffstat (limited to '3rdparty/pybind11/docs/advanced/pycpp/utilities.rst')
-rw-r--r--3rdparty/pybind11/docs/advanced/pycpp/utilities.rst23
1 files changed, 17 insertions, 6 deletions
diff --git a/3rdparty/pybind11/docs/advanced/pycpp/utilities.rst b/3rdparty/pybind11/docs/advanced/pycpp/utilities.rst
index c15051fb..af0f9cb2 100644
--- a/3rdparty/pybind11/docs/advanced/pycpp/utilities.rst
+++ b/3rdparty/pybind11/docs/advanced/pycpp/utilities.rst
@@ -28,7 +28,7 @@ Capturing standard output from ostream
Often, a library will use the streams ``std::cout`` and ``std::cerr`` to print,
but this does not play well with Python's standard ``sys.stdout`` and ``sys.stderr``
-redirection. Replacing a library's printing with `py::print <print>` may not
+redirection. Replacing a library's printing with ``py::print <print>`` may not
be feasible. This can be fixed using a guard around the library function that
redirects output to the corresponding Python streams:
@@ -47,15 +47,26 @@ redirects output to the corresponding Python streams:
call_noisy_func();
});
+.. warning::
+
+ The implementation in ``pybind11/iostream.h`` is NOT thread safe. Multiple
+ threads writing to a redirected ostream concurrently cause data races
+ and potentially buffer overflows. Therefore it is currently a requirement
+ that all (possibly) concurrent redirected ostream writes are protected by
+ a mutex. #HelpAppreciated: Work on iostream.h thread safety. For more
+ background see the discussions under
+ `PR #2982 <https://github.com/pybind/pybind11/pull/2982>`_ and
+ `PR #2995 <https://github.com/pybind/pybind11/pull/2995>`_.
+
This method respects flushes on the output streams and will flush if needed
when the scoped guard is destroyed. This allows the output to be redirected in
real time, such as to a Jupyter notebook. The two arguments, the C++ stream and
the Python output, are optional, and default to standard output if not given. An
-extra type, `py::scoped_estream_redirect <scoped_estream_redirect>`, is identical
+extra type, ``py::scoped_estream_redirect <scoped_estream_redirect>``, is identical
except for defaulting to ``std::cerr`` and ``sys.stderr``; this can be useful with
-`py::call_guard`, which allows multiple items, but uses the default constructor:
+``py::call_guard``, which allows multiple items, but uses the default constructor:
-.. code-block:: py
+.. code-block:: cpp
// Alternative: Call single function using call guard
m.def("noisy_func", &call_noisy_function,
@@ -63,7 +74,7 @@ except for defaulting to ``std::cerr`` and ``sys.stderr``; this can be useful wi
py::scoped_estream_redirect>());
The redirection can also be done in Python with the addition of a context
-manager, using the `py::add_ostream_redirect() <add_ostream_redirect>` function:
+manager, using the ``py::add_ostream_redirect() <add_ostream_redirect>`` function:
.. code-block:: cpp
@@ -92,7 +103,7 @@ arguments to disable one of the streams if needed.
Evaluating Python expressions from strings and files
====================================================
-pybind11 provides the `eval`, `exec` and `eval_file` functions to evaluate
+pybind11 provides the ``eval``, ``exec`` and ``eval_file`` functions to evaluate
Python expressions and statements. The following example illustrates how they
can be used.