Commit 8da6fbe
authored
Add gaurds to redirect C++'s stdout/stderr streams to python's stdout/stderr streams (#68)
C++'s stdout/stderr and Python's stdout/stderr streams are two different
streams.. normally this is not a problem but colab ignores C++'s
streams. To make colab see C++'s streams they need to be redirected to
Python's streams
if the statement `py::call_guard<py::scoped_ostream_redirect,
py::scoped_estream_redirect>()` is added to a function's definition then
its stdout/stderr gets redirected. I do that for the decoding methods
for simplex and tesseract.
so statements like with `verbose=True` will have their stdout redirected
```py3
>> tesseract_dec.decode(...)
len(pq) = 0 num_pq_pushed = 1
num_detectors = 3 max_num_detectors = 65538 cost = 6.811496946171
activated_errors =
activated_detectors = 19, 20, 25,
activated_errors = 880,
activated_detectors =
Decoding complete. Cost: 6.811496946171 num_pq_pushed = 100
```
I also added a context manager that can be used to do this from inside
python
```py3
import tesseract_decoder
with tesseract_decoder.ostream_redirect(stdout=..., stderr=...):
# since the call happens inside the context manager its streams get captured
a_function_whose_stdout_isnot_redirected()
```1 parent f78ce8a commit 8da6fbe
3 files changed
+23
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | | - | |
| 67 | + | |
| 68 | + | |
67 | 69 | | |
68 | 70 | | |
69 | 71 | | |
| |||
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
91 | | - | |
| 93 | + | |
| 94 | + | |
92 | 95 | | |
93 | 96 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
30 | 41 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | | - | |
| 75 | + | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
78 | | - | |
| 80 | + | |
| 81 | + | |
79 | 82 | | |
80 | 83 | | |
81 | 84 | | |
| |||
100 | 103 | | |
101 | 104 | | |
102 | 105 | | |
103 | | - | |
| 106 | + | |
| 107 | + | |
104 | 108 | | |
105 | 109 | | |
106 | 110 | | |
| |||
0 commit comments