close #351. in storm.py: turn off stdout to avoid messing with JSON payload sent back to JAVA layer - #698
close #351. in storm.py: turn off stdout to avoid messing with JSON payload sent back to JAVA layer#698francis-shuoch wants to merge 1 commit into
Conversation
stdout. Meanwhile sendMsgToParent() function doesn't get affected, so the communication to Java Layer is not affected, too. Use this wrapper on any custom python scripts containing prints without worrying those prints would mess up the tuple emits. I tested with storm-starter's WordCountTopology.
|
So developers need to call this |
|
Yes, as lbustelo pointed out in issue #351, custom python function containing prints can use this decorator to wrapper it, so user defined prints won't mess up the tuple emits from the bolts. Like this: sorry I didn't add an example like this in my PR. |
|
Another way is to assign sys.stdout = NullDevice() globally in the module, while sendMsgToParent() use original_stdout so it can write to stdout normally. But this way I don't know when to reassign sys.stdout back. Any thoughts here? I would like to follow it. |
|
Would it be better if |
|
Then I think assigning sys.stdout = NullDevice() globally in the module while only sendMsgToParent() using original_stdout will suffice. What do you think? |
|
About reassigning |
|
I gave it some fresh thoughts today, now I think, since all prints will be read by storm's JVM-component, we must forbid any prints outside of Or, alternatively, we can reassign |
I write a python decorator to silence prints' output into stdout. Meanwhile sendMsgToParent() function doesn't get affected, so the communication to Java Layer is not affected, too. Use this wrapper on any custom python scripts containing prints without worrying those prints would mess up the tuple emits. I tested with storm-starter's WordCountTopology.