Last active
December 20, 2019 15:39
-
-
Save ihnorton/b8863195910c60431427f373e20827e3 to your computer and use it in GitHub Desktop.
demo-flask-app-with-fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
# from https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html#python-flask-create-app | |
libp=b"/opt/python/run/venv/lib64/python3.6/site-packages/tiledb/libtiledb.cpython-36m-x86_64-linux-gnu.so" | |
import os, ctypes, sys | |
ctypes.CDLL(libp, os.RTLD_DEEPBIND) | |
import tiledb | |
# print a nice greeting. | |
def say_hello(username = "World"): | |
txt = '<p>Hello %s!</p>\n' % username | |
txt += '<p>tiledb version is: {}'.format(tiledb.version.version) | |
import subprocess | |
try: | |
extpath = subprocess.check_output(['find', '/opt/python', '-name', 'libtiledb.cpython*']).decode('UTF-8') | |
txt += '<p> extension path is: {}'.format(extpath) | |
except Exception as exc: | |
txt += "got exception: " + str(exc) | |
return txt | |
# some bits of text for the page. | |
header_text = ''' | |
<html>\n<head> <title>EB Flask Test</title> </head>\n<body>''' | |
instructions = ''' | |
<p><em>Hint</em>: This is a RESTful web service! Append a username | |
to the URL (for example: <code>/Thelonious</code>) to say hello to | |
someone specific.</p>\n''' | |
home_link = '<p><a href="/">Back</a></p>\n' | |
footer_text = '</body>\n</html>' | |
# EB looks for an 'application' callable by default. | |
application = Flask(__name__) | |
# add a rule for the index page. | |
application.add_url_rule('/', 'index', (lambda: header_text + | |
say_hello() + instructions + footer_text)) | |
# add a rule when the page is accessed with a name appended to the site | |
# URL. | |
application.add_url_rule('/<username>', 'hello', (lambda username: | |
header_text + say_hello(username) + home_link + footer_text)) | |
# run the app. | |
if __name__ == "__main__": | |
# Setting debug to True enables debug output. This line should be | |
# removed before deploying a production app. | |
application.debug = True | |
application.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/20191218-bruce-eb-segfault/eb-flask/application.py b/20191218-bruce-eb-segfault/eb-flask/application.py | |
index 6b57c83..079a8a6 100644 | |
--- a/20191218-bruce-eb-segfault/eb-flask/application.py | |
+++ b/20191218-bruce-eb-segfault/eb-flask/application.py | |
@@ -1,8 +1,22 @@ | |
from flask import Flask | |
+libp=b"/opt/python/run/venv/lib64/python3.6/site-packages/tiledb/libtiledb.cpython-36m-x86_64-linux-gnu.so" | |
+import os, ctypes, sys | |
+ctypes.CDLL(libp, os.RTLD_DEEPBIND) | |
+ | |
+import tiledb | |
+ | |
# print a nice greeting. | |
def say_hello(username = "World"): | |
- return '<p>Hello %s!</p>\n' % username | |
+ txt = '<p>Hello %s!</p>\n' % username | |
+ txt += '<p>tiledb version is: {}'.format(tiledb.version.version) | |
+ import subprocess | |
+ try: | |
+ extpath = subprocess.check_output(['find', '/opt/python', '-name', 'libtiledb.cpython*']).decode('UTF-8') | |
+ txt += '<p> extension path is: {}'.format(extpath) | |
+ except Exception as exc: | |
+ txt += "got exception: " + str(exc) | |
+ return txt | |
# some bits of text for the page. | |
header_text = ''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Click==7.0 | |
Flask==1.0.2 | |
itsdangerous==1.1.0 | |
Jinja2==2.10.3 | |
MarkupSafe==1.1.1 | |
Werkzeug==0.16.0 | |
tiledb==0.5.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment