Commit fbf03849 authored by J. Fernando Sánchez's avatar J. Fernando Sánchez

Replaced gevent with threading

* Replaced gevent (testing)
* Trying the slim python image (1/3 of previous size)
parent b072121e
Dockerfile-3.4
\ No newline at end of file
Dockerfile-3.5
\ No newline at end of file
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"]
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"]
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"]
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"]
......@@ -7,4 +7,4 @@ graft senpy/plugins
graft senpy/schemas
graft senpy/templates
graft senpy/static
graft img
graft img
\ No newline at end of file
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)
......
......@@ -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))
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment