summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2016-08-26 17:00:33 +0200
committerGitHub <noreply@github.com>2016-08-26 17:00:33 +0200
commit3d3a3ad60b6b0e90678524b1cf1752626800f7a9 (patch)
tree797e0058843b0120c5e54d3288c2d50cd4eabfd8
parent9772d84063684ce95df2c495cd7ef0fad2f7b9f5 (diff)
parent70368391c045f57a7b1b643c826da2b7c6da77dc (diff)
downloadbottle-travis-server-tests.tar.gz
Merge pull request #868 from sideffect0/devtravis-server-tests
Add Support for UVLoop and custom asyncio loop option
-rw-r--r--bottle.py20
-rw-r--r--test/test_server.py3
2 files changed, 21 insertions, 2 deletions
diff --git a/bottle.py b/bottle.py
index 492b4f0..4ce2229 100644
--- a/bottle.py
+++ b/bottle.py
@@ -3300,17 +3300,25 @@ class BjoernServer(ServerAdapter):
from bjoern import run
run(handler, self.host, self.port)
+class AsyncioServerAdapter(ServerAdapter):
+ """ Extend ServerAdapter for adding custom event loop """
+ def get_event_loop(self):
+ pass
-class AiohttpServer(ServerAdapter):
+class AiohttpServer(AsyncioServerAdapter):
""" Untested.
aiohttp
https://pypi.python.org/pypi/aiohttp/
"""
+ def get_event_loop(self):
+ import asyncio
+ return asyncio.new_event_loop()
+
def run(self, handler):
import asyncio
from aiohttp.wsgi import WSGIServerHttpProtocol
- self.loop = asyncio.new_event_loop()
+ self.loop = self.get_event_loop()
asyncio.set_event_loop(self.loop)
protocol_factory = lambda: WSGIServerHttpProtocol(
@@ -3330,6 +3338,13 @@ class AiohttpServer(ServerAdapter):
except KeyboardInterrupt:
self.loop.stop()
+class AiohttpUVLoopServer(AiohttpServer):
+ """uvloop
+ https://github.com/MagicStack/uvloop
+ """
+ def get_event_loop(self):
+ import uvloop
+ return uvloop.new_event_loop()
class AutoServer(ServerAdapter):
""" Untested. """
@@ -3364,6 +3379,7 @@ server_names = {
'rocket': RocketServer,
'bjoern': BjoernServer,
'aiohttp': AiohttpServer,
+ 'uvloop': AiohttpUVLoopServer,
'auto': AutoServer,
}
diff --git a/test/test_server.py b/test/test_server.py
index c89bb5a..b566e27 100644
--- a/test/test_server.py
+++ b/test/test_server.py
@@ -129,3 +129,6 @@ class TestBjoernServer(TestServer):
class TestAiohttpServer(TestServer):
server = 'aiohttp'
+
+class TestAiohttpServer(TestServer):
+ server = 'uvloop'