From 60926a3af19cccf9865f44c70c2cafa7a98c97aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sat, 7 Dec 2019 12:15:01 +0100 Subject: [PATCH] python sleep type function --- sleep-python/.dockerignore | 6 ++++++ sleep-python/.idea/.gitignore | 2 ++ .../inspectionProfiles/profiles_settings.xml | 6 ++++++ sleep-python/.idea/isprime-python.iml | 20 +++++++++++++++++++ .../.idea/libraries/R_User_Library.xml | 6 ++++++ sleep-python/.idea/misc.xml | 7 +++++++ sleep-python/.idea/modules.xml | 8 ++++++++ sleep-python/.idea/vcs.xml | 6 ++++++ sleep-python/Dockerfile | 17 ++++++++++++++++ sleep-python/app.py | 19 ++++++++++++++++++ 10 files changed, 97 insertions(+) create mode 100644 sleep-python/.dockerignore create mode 100644 sleep-python/.idea/.gitignore create mode 100644 sleep-python/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 sleep-python/.idea/isprime-python.iml create mode 100644 sleep-python/.idea/libraries/R_User_Library.xml create mode 100644 sleep-python/.idea/misc.xml create mode 100644 sleep-python/.idea/modules.xml create mode 100644 sleep-python/.idea/vcs.xml create mode 100644 sleep-python/Dockerfile create mode 100644 sleep-python/app.py diff --git a/sleep-python/.dockerignore b/sleep-python/.dockerignore new file mode 100644 index 0000000..3322b45 --- /dev/null +++ b/sleep-python/.dockerignore @@ -0,0 +1,6 @@ +Dockerfile +README.md +*.pyc +*.pyo +*.pyd +__pycache__ diff --git a/sleep-python/.idea/.gitignore b/sleep-python/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/sleep-python/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/sleep-python/.idea/inspectionProfiles/profiles_settings.xml b/sleep-python/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/sleep-python/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/sleep-python/.idea/isprime-python.iml b/sleep-python/.idea/isprime-python.iml new file mode 100644 index 0000000..c30daf7 --- /dev/null +++ b/sleep-python/.idea/isprime-python.iml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sleep-python/.idea/libraries/R_User_Library.xml b/sleep-python/.idea/libraries/R_User_Library.xml new file mode 100644 index 0000000..71f5ff7 --- /dev/null +++ b/sleep-python/.idea/libraries/R_User_Library.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/sleep-python/.idea/misc.xml b/sleep-python/.idea/misc.xml new file mode 100644 index 0000000..8656114 --- /dev/null +++ b/sleep-python/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/sleep-python/.idea/modules.xml b/sleep-python/.idea/modules.xml new file mode 100644 index 0000000..b1716f3 --- /dev/null +++ b/sleep-python/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/sleep-python/.idea/vcs.xml b/sleep-python/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/sleep-python/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/sleep-python/Dockerfile b/sleep-python/Dockerfile new file mode 100644 index 0000000..9d563ca --- /dev/null +++ b/sleep-python/Dockerfile @@ -0,0 +1,17 @@ +# Use the official lightweight Python image. +# https://hub.docker.com/_/python +FROM python:3.7-slim + +# Copy local code to the container image. +ENV APP_HOME /app +WORKDIR $APP_HOME + +# Install production dependencies. +RUN pip install --no-cache-dir Flask gunicorn + +COPY . ./ +# Run the web service on container startup. Here we use the gunicorn +# webserver, with one worker process and 8 threads. +# For environments with multiple CPU cores, increase the number of workers +# to be equal to the cores available. +CMD exec gunicorn --bind :$PORT --workers 1 --threads 1 app:app diff --git a/sleep-python/app.py b/sleep-python/app.py new file mode 100644 index 0000000..bf375ac --- /dev/null +++ b/sleep-python/app.py @@ -0,0 +1,19 @@ +import os +import time +from flask import Flask + +app = Flask(__name__) + +def safe_cast(val, to_type, default=107107): + try: + return to_type(val) + except (ValueError, TypeError): + return default + +@app.route('/') +def sleeper(): + time.sleep(0.1) + return "Slept well" + +if __name__ == "__main__": + app.run(debug=True,host='0.0.0.0',port=int(os.environ.get('PORT', 8080)))