Adding PyGILState_Check() in object_api<>::operator(). (#2919)

* Adding PyGILState_Check() in object_api<>::operator().

* Enabling PyGILState_Check() for Python >= 3.6 only.

Possibly, this explains why PyGILState_Check() cannot safely be used with Python 3.4 and 3.5:

https://github.com/python/cpython/pull/10267#issuecomment-434881587

* Adding simple micro benchmark.

* Reducing test time to minimum (purely for coverage, not for accurate results).

* Fixing silly oversight.

* Minor code organization improvement in test.

* Adding example runtimes.

* Removing capsys (just run with `-k test_callback_num_times -s` and using `.format()`.
This commit is contained in:
Ralf W. Grosse-Kunstleve
2021-04-02 18:17:12 -07:00
committed by GitHub
parent f676782bec
commit ad6bf5cd39
3 changed files with 43 additions and 0 deletions

View File

@@ -172,4 +172,10 @@ TEST_SUBMODULE(callbacks, m) {
for (auto i : work)
start_f(py::cast<int>(i));
});
m.def("callback_num_times", [](py::function f, std::size_t num) {
for (std::size_t i = 0; i < num; i++) {
f();
}
});
}