Commit c2e89052 authored by Jim Fulton's avatar Jim Fulton

Got uvloop working with the mtacceptor

thanks to the new connect_accepted_socket API.

Abstracted the code that supports using asyncio vs trollius vs uvloop
parent 49bc8e46
......@@ -128,7 +128,7 @@ setup(name="ZEO",
classifiers = classifiers,
test_suite="__main__.alltests", # to support "setup.py test"
tests_require = tests_require,
extras_require = dict(test=tests_require, uvloop=['uvloop']),
extras_require = dict(test=tests_require, uvloop=['uvloop >=0.5.1']),
install_requires = install_requires,
zip_safe = False,
entry_points = """
......
from .._compat import PY3
if PY3:
import asyncio
try:
from uvloop import new_event_loop
except ImportError:
from asyncio import new_event_loop
else:
import trollius as asyncio
from trollius import new_event_loop
from ZEO.Exceptions import ClientDisconnected, ServerException
import concurrent.futures
import functools
......@@ -24,6 +12,7 @@ import ZEO.Exceptions
import ZEO.interfaces
from . import base
from .compat import asyncio, new_event_loop
from .marshal import decode
logger = logging.getLogger(__name__)
......
......@@ -41,18 +41,12 @@ with::
in ZEO.StorageServer.
"""
from .._compat import PY3
if PY3:
import asyncio
else:
import trollius as asyncio
import asyncore
import socket
import threading
import time
from .compat import asyncio, new_event_loop
from .server import ServerProtocol
# _has_dualstack: True if the dual-stack sockets are supported
......@@ -169,8 +163,7 @@ class Acceptor(asyncore.dispatcher):
logger.debug("new connection %s" % (addr,))
def run():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop = new_event_loop()
zs = self.storage_server.create_client_handler()
protocol = ServerProtocol(loop, self.addr, zs)
protocol.stop = loop.stop
......@@ -179,7 +172,7 @@ class Acceptor(asyncore.dispatcher):
cr = loop.create_connection((lambda : protocol), sock=sock)
else:
if hasattr(loop, 'connect_accepted_socket'):
loop.connect_accepted_socket(
cr = loop.connect_accepted_socket(
(lambda : protocol), sock, ssl=self.ssl_context)
else:
#######################################################
......
from .._compat import PY3
if PY3:
import asyncio
try:
from uvloop import new_event_loop
except ImportError:
from asyncio import new_event_loop
else:
import trollius as asyncio
from trollius import new_event_loop
import json
import logging
import os
......@@ -22,6 +10,7 @@ logger = logging.getLogger(__name__)
from ..shortrepr import short_repr
from . import base
from .compat import asyncio, new_event_loop
from .marshal import server_decode
class ServerProtocol(base.Protocol):
......
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