我正在尝试在Alpine docker image(3.9)上启动一个简单的uWSGI服务器。这是Python脚本
import hashlib
import os
from urllib.parse import urlparse
import zipfile
import tempfile
import subprocess
from pathlib import Path
import pandas as pd
import requests
DATA_DIR = Path(save_cache_path('yourdatadirname'))
if not DATA_DIR.exists():
os.mkdir(DATA_DIR)
def hash(s):
try:
return hashlib.sha256(s).hexdigest()
except TypeError:
return hashlib.sha256(s.encode('utf-8')).hexdigest()
def delete_cached_file(url):
'''
Helper function to delete an erroneous file or something like that..
'''
filename = DATA_DIR / hash(url)
os.remove(filename)
def ssh_file(url):
filename = DATA_DIR / hash(url)
if not filename.exists():
subprocess.run(['scp', url, filename])
return filename
def http_file(url, zip_extract_name=None):
'''
Automatically downloads a URL (if not cached) and provides the file path;
Also tries to automatically unzip files (only works with ZIP files containing a single file with the correct naming..)
:zip_extract_name: extract the specified filename from a ZIP file
'''
filename = DATA_DIR / hash(url)
if not filename.exists():
r = requests.get(url, allow_redirects=True)
url_filename = os.path.basename(urlparse(url).path)
inner_url_filename, ext = os.path.splitext(filename)
if zip_extract_name:
# if ext == '.zip':
zf = tempfile.NamedTemporaryFile(delete=False)
zf.write(r.content)
zf.close()
with zipfile.ZipFile(zf.name, 'r') as zipped_file:
data = zipped_file.read(zip_extract_name)
else:
data = r.content
with open(filename, 'wb') as f:
f.write(data)
return filename
我正在尝试使用以下命令启动它:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]
但是,每次尝试此操作都会出现此错误:
uwsgi --plugins http,python3,gevent --http :8081 --uid nobody --gid nobody --wsgi-file hello.py --module hello --master --processes 4 --gevent 2 --gevent-monkey-patch --socket /tmp/uswgi.sock
我尝试安装!!! UNABLE to load uWSGI plugin: Error relocating /usr/lib/uwsgi/gevent_plugin.so: PyInt_FromLong: symbol not found !!!
uwsgi: unrecognized option: gevent
getopt_long() error
软件包,但是命令仍然失败。有谁知道为什么会这样?这是我的Dockerfile:
python3-dev
答案 0 :(得分:1)
RUN apk add --no-cache --update \
python3 \
python3-dev \
py3-gevent \
uwsgi \
uwsgi-python3 \
uwsgi-http \
uwsgi-gevent3
是Python 2 uWSGI插件:
https://pkgs.alpinelinux.org/package/v3.9/main/x86_64/uwsgi-gevent
对于Python 3,您需要uwsgi-gevent3
。
此外,您缺少gevent Python模块的py3-gevent
软件包。
总而言之,更新的软件包列表:
gevent3
此外,别忘了使用gevent
插件代替uwsgi --plugins http,python3,gevent3
:
puma.rb