Skip to content

Commit

Permalink
runtimes/python: Added support for providing stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
anandology committed Feb 28, 2022
1 parent ba5ac48 commit 42d547e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtimes/python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ WORKDIR /app
COPY run.sh /opt/
COPY runtests.py /opt/
COPY modes /opt/modes/
COPY sitecustomize.py /usr/local/lib/python3.9/
ENTRYPOINT ["/opt/run.sh"]
27 changes: 27 additions & 0 deletions runtimes/python/sitecustomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def _customize():
import os
import sys
import io
import json
import builtins

FALCON_STDIN = os.getenv("FALCON_STDIN")
if not FALCON_STDIN:
return
try:
stdin_json = '"' + FALCON_STDIN + '"'
except ValueError:
stdin_json = '""'
stdin_text = json.loads(stdin_json)
sys.stdin = io.StringIO(stdin_text)

def _input(prompt=None):
if prompt:
print(prompt, end="")
line = sys.stdin.readline().strip("\n")
print(line)
return line
builtins.input = _input

_customize()
del _customize

0 comments on commit 42d547e

Please sign in to comment.