File tree Expand file tree Collapse file tree 4 files changed +20
-5
lines changed
Expand file tree Collapse file tree 4 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -12929,6 +12929,22 @@ def forward(self, key):
1292912929 .check_count(s2, 1, exactly=True) \
1293012930 .check_count("BINGET", 2, exactly=True).run(out.getvalue())
1293112931
12932+ def test_sys_stdout_override(self):
12933+ @torch.jit.script
12934+ def foo():
12935+ print('foo')
12936+
12937+ old_stdout = sys.stdout
12938+ with tempfile.TemporaryFile() as f:
12939+ try:
12940+ sys.stdout = f
12941+ foo()
12942+ finally:
12943+ sys.stdout = old_stdout
12944+
12945+ f.seek(0)
12946+ FileCheck().check('foo').run(f.read())
12947+
1293212948 def test_optional_tuple(self):
1293312949 def fn(x=None):
1293412950 # type: (Optional[Tuple[int, int]]) -> Tuple[int, int]
Original file line number Diff line number Diff line change 5454
5555#include < ATen/core/function_schema.h>
5656
57- #include < Python.h>
5857#include < pybind11/functional.h>
58+ #include < pybind11/iostream.h>
5959
6060#include < memory>
6161#include < sstream>
@@ -570,7 +570,7 @@ void initJITBindings(PyObject* module) {
570570 setPrintHandler ([](const std::string& str) {
571571 py::gil_scoped_acquire acquire;
572572 auto _stdout = py::module::import (" sys" ).attr (" stdout" );
573- _stdout.attr (" write" )(str);
573+ _stdout.attr (" write" )(py::bytes ( str) );
574574 });
575575}
576576} // namespace jit
Original file line number Diff line number Diff line change 11#pragma once
22
3- #include < functional>
4- #include < iostream>
5-
63namespace torch {
74namespace jit {
85
Original file line number Diff line number Diff line change 11#include < torch/csrc/jit/print_handler.h>
22
3+ #include < iostream>
4+
35namespace torch {
46namespace jit {
57
You can’t perform that action at this time.
0 commit comments