24 std::cout << std::flush;
38 auto thread_f = [
this] {
39 static std::mutex cout_mutex;
48 const std::lock_guard<std::mutex> lock(cout_mutex);
49 std::cout <<
"x" << std::flush;
51 std::this_thread::sleep_for(std::chrono::microseconds(50));
54 t_ =
new std::thread(std::move(thread_f));
62 py::gil_scoped_release gil_lock;
67 py::gil_scoped_release gil_lock;
68 std::this_thread::sleep_for(std::chrono::milliseconds(50));
71 std::thread *
t_{
nullptr};
81 m.def(
"captured_output_default", [](
const std::string &
msg) {
82 py::scoped_ostream_redirect redir;
83 std::cout << msg << std::flush;
86 m.def(
"captured_output", [](
const std::string &msg) {
87 py::scoped_ostream_redirect redir(std::cout, py::module_::import(
"sys").attr(
"stdout"));
88 std::cout << msg << std::flush;
93 py::call_guard<py::scoped_ostream_redirect>(),
97 m.def(
"captured_err", [](
const std::string &msg) {
98 py::scoped_ostream_redirect redir(std::cerr, py::module_::import(
"sys").attr(
"stderr"));
99 std::cerr << msg << std::flush;
106 py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>(),
110 m.def(
"raw_output", [](
const std::string &msg) { std::cout << msg << std::flush; });
112 m.def(
"raw_err", [](
const std::string &msg) { std::cerr << msg << std::flush; });
114 m.def(
"captured_dual", [](
const std::string &msg,
const std::string &emsg) {
115 py::scoped_ostream_redirect redirout(std::cout, py::module_::import(
"sys").attr(
"stdout"));
116 py::scoped_ostream_redirect redirerr(std::cerr, py::module_::import(
"sys").attr(
"stderr"));
117 std::cout << msg << std::flush;
118 std::cerr << emsg << std::flush;
121 py::class_<TestThread>(
m,
"TestThread")
void noisy_funct_dual(const std::string &msg, const std::string &emsg)
std::atomic< bool > stop_
class_< detail::OstreamRedirect > add_ostream_redirect(module_ m, const std::string &name="ostream_redirect")
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
TEST_SUBMODULE(iostream, m)
void noisy_function(const std::string &msg, bool flush)