Skip to content

Commit

Permalink
python_bindings: acquire GIL before printing
Browse files Browse the repository at this point in the history
  • Loading branch information
knzivid committed Mar 4, 2022
1 parent 3827279 commit 635c74e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions python_bindings/correctness/realize_warnings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import halide as hl
from io import StringIO
from contextlib import redirect_stdout


def test_warnings():
i = hl.Var()
f = hl.Func("f")
f[i] = 0.0
f.bound(i, 0, 127)

g = hl.Func("g")
g[i] = f[i * i]

expected_warning = "Warning: It is meaningless to bound dimension v0 of function f to be within [0, 127] because " \
"the function is scheduled inline.\n"

buffer = StringIO()
with redirect_stdout(buffer):
g.realize([16])

buffer.seek(0)
stdout_lines = buffer.readlines()
assert stdout_lines == [expected_warning] * 3


if __name__ == '__main__':
test_warnings()
2 changes: 1 addition & 1 deletion python_bindings/src/PyError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void halide_python_print(JITUserContext *, const char *msg) {
class HalidePythonCompileTimeErrorReporter : public CompileTimeErrorReporter {
public:
void warning(const char *msg) override {
py::print(msg, py::arg("end") = "");
halide_python_print(nullptr, msg);
}

void error(const char *msg) override {
Expand Down

0 comments on commit 635c74e

Please sign in to comment.