Skip to content

Commit

Permalink
feat: add encoding and replace stderr for ws
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed Jul 15, 2024
1 parent d676f30 commit 026e1f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/funix/app/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class StdoutToWebsocket:
"""
Stdout to websocket.
"""

encoding = "utf-8"

def __init__(self, ws):
"""
Expand Down
3 changes: 3 additions & 0 deletions backend/funix/decorator/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ def wrapped_function(**wrapped_function_kwargs):
def output_to_web_function(**wrapped_function_kwargs):
try:
fake_stdout = StdoutToWebsocket(ws)
fake_stderr = StdoutToWebsocket(ws)
org_stdout, sys.stdout = sys.stdout, fake_stdout
org_stderr, sys.stderr = sys.stderr, fake_stderr
if isgeneratorfunction(function):
for single_result in function(**wrapped_function_kwargs):
if single_result:
Expand All @@ -193,6 +195,7 @@ def output_to_web_function(**wrapped_function_kwargs):
else:
print(function_result_)
sys.stdout = org_stdout
sys.stderr = org_stderr
except:
ws.send(
dumps(
Expand Down

0 comments on commit 026e1f4

Please sign in to comment.