Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close #351. in storm.py: turn off stdout to avoid messing with JSON payload sent back to JAVA layer #698

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions storm-core/src/multilang/py/storm.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def readTuple():
return Tuple(cmd["id"], cmd["comp"], cmd["stream"], cmd["task"], cmd["tuple"])

def sendMsgToParent(msg):
print json_encode(msg)
print "end"
sys.stdout.flush()
original_stdout.write(json_encode(msg) + '\n')
original_stdout.write("end\n")
original_stdout.flush()

def sync():
sendMsgToParent({'command':'sync'})
Expand Down Expand Up @@ -123,6 +123,28 @@ def initComponent():
sendpid(setupInfo['pidDir'])
return [setupInfo['conf'], setupInfo['context']]

# prevent custom code's print methods pollute stdout, resulting in wrong
# message sent to JAVA layer.

original_stdout = sys.stdout

def nullify_stdout(func):
# a wrapper function nullify all print methods of its wrapped funcs.

class NullDevice():
def write(self, s):
pass

def wrapper(*args):
sys.stdout = NullDevice()
try:
result = func(*args)
finally:
sys.stdout = original_stdout
return result

return wrapper

class Tuple(object):
def __init__(self, id, component, stream, task, values):
self.id = id
Expand Down