10 #if defined(_MSC_VER) && _MSC_VER < 1910 // VS 2015's MSVC
11 # pragma warning(disable: 4702) // unreachable code in system header (xatomic.h(382))
25 std::cout << std::flush;
38 auto thread_f = [
this] {
40 std::cout <<
"x" << std::flush;
41 std::this_thread::sleep_for(std::chrono::microseconds(50));
53 py::gil_scoped_release gil_lock;
58 py::gil_scoped_release gil_lock;
59 std::this_thread::sleep_for(std::chrono::milliseconds(50));
73 m.def(
"captured_output_default", [](std::string
msg) {
74 py::scoped_ostream_redirect redir;
75 std::cout <<
msg << std::flush;
78 m.def(
"captured_output", [](std::string
msg) {
79 py::scoped_ostream_redirect redir(std::cout, py::module_::import(
"sys").attr(
"stdout"));
80 std::cout <<
msg << std::flush;
84 py::call_guard<py::scoped_ostream_redirect>(),
85 py::arg(
"msg"), py::arg(
"flush")=
true);
87 m.def(
"captured_err", [](std::string
msg) {
88 py::scoped_ostream_redirect redir(std::cerr, py::module_::import(
"sys").attr(
"stderr"));
89 std::cerr <<
msg << std::flush;
92 m.def(
"noisy_function", &
noisy_function, py::arg(
"msg"), py::arg(
"flush") =
true);
95 py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>(),
96 py::arg(
"msg"), py::arg(
"emsg"));
98 m.def(
"raw_output", [](std::string
msg) {
99 std::cout <<
msg << std::flush;
102 m.def(
"raw_err", [](std::string
msg) {
103 std::cerr <<
msg << std::flush;
106 m.def(
"captured_dual", [](std::string
msg, std::string emsg) {
107 py::scoped_ostream_redirect redirout(std::cout, py::module_::import(
"sys").attr(
"stdout"));
108 py::scoped_ostream_redirect redirerr(std::cerr, py::module_::import(
"sys").attr(
"stderr"));
109 std::cout <<
msg << std::flush;
110 std::cerr << emsg << std::flush;
113 py::class_<TestThread>(
m,
"TestThread")