mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-13 04:02:29 +00:00
Replaced gevent with threading
* Replaced gevent (testing) * Trying the slim python image (1/3 of previous size)
This commit is contained in:
parent
b072121e20
commit
fbf0384985
@ -1 +1 @@
|
|||||||
Dockerfile-3.4
|
Dockerfile-3.5
|
@ -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 .
|
RUN pip install .
|
||||||
|
|
||||||
ENTRYPOINT ["python", "-m", "senpy", "-f", ".", "--host", "0.0.0.0"]
|
ENTRYPOINT ["python", "-m", "senpy", "-f", ".", "--host", "0.0.0.0"]
|
||||||
|
@ -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 .
|
RUN pip install .
|
||||||
|
|
||||||
ENTRYPOINT ["python", "-m", "senpy", "-f", ".", "--host", "0.0.0.0"]
|
ENTRYPOINT ["python", "-m", "senpy", "-f", ".", "--host", "0.0.0.0"]
|
||||||
|
9
Dockerfile-3.5
Normal file
9
Dockerfile-3.5
Normal 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"]
|
@ -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 .
|
RUN pip install .
|
||||||
|
|
||||||
ENTRYPOINT ["python", "-m", "senpy", "-f", ".", "--host", "0.0.0.0"]
|
ENTRYPOINT ["python", "-m", "senpy", "-f", ".", "--host", "0.0.0.0"]
|
||||||
|
5
Makefile
5
Makefile
@ -1,4 +1,4 @@
|
|||||||
PYVERSIONS=3.4 2.7
|
PYVERSIONS=3.5 3.4 2.7
|
||||||
PYMAIN=$(firstword $(PYVERSIONS))
|
PYMAIN=$(firstword $(PYVERSIONS))
|
||||||
NAME=senpy
|
NAME=senpy
|
||||||
REPO=gsiupm
|
REPO=gsiupm
|
||||||
@ -16,6 +16,7 @@ dev:
|
|||||||
pre-commit install
|
pre-commit install
|
||||||
|
|
||||||
dockerfiles: $(addprefix Dockerfile-,$(PYVERSIONS))
|
dockerfiles: $(addprefix Dockerfile-,$(PYVERSIONS))
|
||||||
|
@unlink Dockerfile >/dev/null
|
||||||
ln -s Dockerfile-$(PYMAIN) Dockerfile
|
ln -s Dockerfile-$(PYMAIN) Dockerfile
|
||||||
|
|
||||||
Dockerfile-%: Dockerfile.template
|
Dockerfile-%: Dockerfile.template
|
||||||
@ -35,7 +36,7 @@ test: $(addprefix test-,$(PYMAIN))
|
|||||||
|
|
||||||
testall: $(addprefix test-,$(PYVERSIONS))
|
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 ;
|
docker run --rm -w /usr/src/app/ -v $$PWD:/usr/src/app --entrypoint=/bin/bash -ti $(NAME)-debug ;
|
||||||
|
|
||||||
debug: debug-$(PYMAIN)
|
debug: debug-$(PYMAIN)
|
||||||
|
@ -1 +1 @@
|
|||||||
0.7.0-dev2
|
0.7.0-dev3
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
"""
|
"""
|
||||||
from future import standard_library
|
from future import standard_library
|
||||||
standard_library.install_aliases()
|
standard_library.install_aliases()
|
||||||
import gevent
|
|
||||||
from gevent import monkey
|
|
||||||
monkey.patch_all()
|
|
||||||
|
|
||||||
from .plugins import SentimentPlugin
|
from .plugins import SentimentPlugin
|
||||||
from .models import Error
|
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 .api import API_PARAMS, NIF_PARAMS, parse_params
|
||||||
|
|
||||||
from git import Repo, InvalidGitRepositoryError
|
from git import Repo, InvalidGitRepositoryError
|
||||||
from functools import partial
|
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import fnmatch
|
import fnmatch
|
||||||
@ -154,20 +152,23 @@ class Senpy(object):
|
|||||||
logger.info("Activating plugin: {}".format(plugin.name))
|
logger.info("Activating plugin: {}".format(plugin.name))
|
||||||
|
|
||||||
def act():
|
def act():
|
||||||
|
success = False
|
||||||
try:
|
try:
|
||||||
plugin.activate()
|
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:
|
except Exception as ex:
|
||||||
logger.error("Error activating plugin {}: {}".format(
|
msg = "Error activating plugin {} - {} : \n\t{}".format(
|
||||||
plugin.name, ex))
|
plugin.name, ex, ex.format_exc())
|
||||||
logger.error("Trace: {}".format(traceback.format_exc()))
|
logger.error(msg)
|
||||||
|
raise Error(msg)
|
||||||
th = gevent.spawn(act)
|
|
||||||
th.link_value(partial(self._set_active_plugin, plugin_name, True))
|
|
||||||
if sync:
|
if sync:
|
||||||
th.join()
|
act()
|
||||||
else:
|
else:
|
||||||
return th
|
th = Thread(target=act)
|
||||||
|
th.start()
|
||||||
|
|
||||||
def deactivate_plugin(self, plugin_name, sync=False):
|
def deactivate_plugin(self, plugin_name, sync=False):
|
||||||
try:
|
try:
|
||||||
@ -176,6 +177,8 @@ class Senpy(object):
|
|||||||
raise Error(
|
raise Error(
|
||||||
message="Plugin not found: {}".format(plugin_name), status=404)
|
message="Plugin not found: {}".format(plugin_name), status=404)
|
||||||
|
|
||||||
|
self._set_active_plugin(plugin_name, False)
|
||||||
|
|
||||||
def deact():
|
def deact():
|
||||||
try:
|
try:
|
||||||
plugin.deactivate()
|
plugin.deactivate()
|
||||||
@ -185,12 +188,11 @@ class Senpy(object):
|
|||||||
plugin.name, ex))
|
plugin.name, ex))
|
||||||
logger.error("Trace: {}".format(traceback.format_exc()))
|
logger.error("Trace: {}".format(traceback.format_exc()))
|
||||||
|
|
||||||
th = gevent.spawn(deact)
|
|
||||||
th.link_value(partial(self._set_active_plugin, plugin_name, False))
|
|
||||||
if sync:
|
if sync:
|
||||||
th.join()
|
deact()
|
||||||
else:
|
else:
|
||||||
return th
|
th = Thread(target=deact)
|
||||||
|
th.start()
|
||||||
|
|
||||||
def reload_plugin(self, name):
|
def reload_plugin(self, name):
|
||||||
logger.debug("Reloading {}".format(name))
|
logger.debug("Reloading {}".format(name))
|
||||||
|
7
setup.py
7
setup.py
@ -23,10 +23,9 @@ setup(
|
|||||||
name='senpy',
|
name='senpy',
|
||||||
packages=['senpy'], # this must be the same as the name above
|
packages=['senpy'], # this must be the same as the name above
|
||||||
version=__version__,
|
version=__version__,
|
||||||
description='''
|
description=('A sentiment analysis server implementation. '
|
||||||
A sentiment analysis server implementation. Designed to be \
|
'Designed to be extensible, so new algorithms '
|
||||||
extendable, so new algorithms and sources can be used.
|
'and sources can be used.'),
|
||||||
''',
|
|
||||||
author='J. Fernando Sanchez',
|
author='J. Fernando Sanchez',
|
||||||
author_email='balkian@gmail.com',
|
author_email='balkian@gmail.com',
|
||||||
url='https://github.com/gsi-upm/senpy', # use the URL to the github repo
|
url='https://github.com/gsi-upm/senpy', # use the URL to the github repo
|
||||||
|
Loading…
Reference in New Issue
Block a user