1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-11-21 15:52:28 +00:00

Replaced gevent with threading

* Replaced gevent (testing)
* Trying the slim python image (1/3 of previous size)
This commit is contained in:
J. Fernando Sánchez 2017-02-02 16:35:58 +01:00
parent b072121e20
commit fbf0384985
10 changed files with 52 additions and 29 deletions

View File

@ -1 +1 @@
Dockerfile-3.4
Dockerfile-3.5

View File

@ -1,5 +1,9 @@
from python:2.7-onbuild
from python:2.7-slim
WORKDIR /usr/src/app
ADD requirements.txt /usr/src/app/
RUN pip install -r requirements.txt
ADD . /usr/src/app/
RUN pip install .
ENTRYPOINT ["python", "-m", "senpy", "-f", ".", "--host", "0.0.0.0"]

View File

@ -1,5 +1,9 @@
from python:3.4-onbuild
from python:3.4-slim
WORKDIR /usr/src/app
ADD requirements.txt /usr/src/app/
RUN pip install -r requirements.txt
ADD . /usr/src/app/
RUN pip install .
ENTRYPOINT ["python", "-m", "senpy", "-f", ".", "--host", "0.0.0.0"]

9
Dockerfile-3.5 Normal file
View File

@ -0,0 +1,9 @@
from python:3.5-slim
WORKDIR /usr/src/app
ADD requirements.txt /usr/src/app/
RUN pip install -r requirements.txt
ADD . /usr/src/app/
RUN pip install .
ENTRYPOINT ["python", "-m", "senpy", "-f", ".", "--host", "0.0.0.0"]

View File

@ -1,5 +1,9 @@
from python:{{PYVERSION}}-onbuild
from python:{{PYVERSION}}-slim
WORKDIR /usr/src/app
ADD requirements.txt /usr/src/app/
RUN pip install -r requirements.txt
ADD . /usr/src/app/
RUN pip install .
ENTRYPOINT ["python", "-m", "senpy", "-f", ".", "--host", "0.0.0.0"]

View File

@ -7,4 +7,4 @@ graft senpy/plugins
graft senpy/schemas
graft senpy/templates
graft senpy/static
graft img
graft img

View File

@ -1,4 +1,4 @@
PYVERSIONS=3.4 2.7
PYVERSIONS=3.5 3.4 2.7
PYMAIN=$(firstword $(PYVERSIONS))
NAME=senpy
REPO=gsiupm
@ -16,6 +16,7 @@ dev:
pre-commit install
dockerfiles: $(addprefix Dockerfile-,$(PYVERSIONS))
@unlink Dockerfile >/dev/null
ln -s Dockerfile-$(PYMAIN) Dockerfile
Dockerfile-%: Dockerfile.template
@ -35,7 +36,7 @@ test: $(addprefix test-,$(PYMAIN))
testall: $(addprefix test-,$(PYVERSIONS))
debug-%: build-debug-%
debug-%:
docker run --rm -w /usr/src/app/ -v $$PWD:/usr/src/app --entrypoint=/bin/bash -ti $(NAME)-debug ;
debug: debug-$(PYMAIN)

View File

@ -1 +1 @@
0.7.0-dev2
0.7.0-dev3

View File

@ -2,9 +2,6 @@
"""
from future import standard_library
standard_library.install_aliases()
import gevent
from gevent import monkey
monkey.patch_all()
from .plugins import SentimentPlugin
from .models import Error
@ -12,7 +9,8 @@ from .blueprints import api_blueprint, demo_blueprint
from .api import API_PARAMS, NIF_PARAMS, parse_params
from git import Repo, InvalidGitRepositoryError
from functools import partial
from threading import Thread
import os
import fnmatch
@ -154,20 +152,23 @@ class Senpy(object):
logger.info("Activating plugin: {}".format(plugin.name))
def act():
success = False
try:
plugin.activate()
logger.info("Plugin activated: {}".format(plugin.name))
msg = "Plugin activated: {}".format(plugin.name)
logger.info(msg)
success = True
self._set_active_plugin(plugin_name, success)
except Exception as ex:
logger.error("Error activating plugin {}: {}".format(
plugin.name, ex))
logger.error("Trace: {}".format(traceback.format_exc()))
th = gevent.spawn(act)
th.link_value(partial(self._set_active_plugin, plugin_name, True))
msg = "Error activating plugin {} - {} : \n\t{}".format(
plugin.name, ex, ex.format_exc())
logger.error(msg)
raise Error(msg)
if sync:
th.join()
act()
else:
return th
th = Thread(target=act)
th.start()
def deactivate_plugin(self, plugin_name, sync=False):
try:
@ -176,6 +177,8 @@ class Senpy(object):
raise Error(
message="Plugin not found: {}".format(plugin_name), status=404)
self._set_active_plugin(plugin_name, False)
def deact():
try:
plugin.deactivate()
@ -185,12 +188,11 @@ class Senpy(object):
plugin.name, ex))
logger.error("Trace: {}".format(traceback.format_exc()))
th = gevent.spawn(deact)
th.link_value(partial(self._set_active_plugin, plugin_name, False))
if sync:
th.join()
deact()
else:
return th
th = Thread(target=deact)
th.start()
def reload_plugin(self, name):
logger.debug("Reloading {}".format(name))

View File

@ -23,10 +23,9 @@ setup(
name='senpy',
packages=['senpy'], # this must be the same as the name above
version=__version__,
description='''
A sentiment analysis server implementation. Designed to be \
extendable, so new algorithms and sources can be used.
''',
description=('A sentiment analysis server implementation. '
'Designed to be extensible, so new algorithms '
'and sources can be used.'),
author='J. Fernando Sanchez',
author_email='balkian@gmail.com',
url='https://github.com/gsi-upm/senpy', # use the URL to the github repo