diff --git a/aioelasticsearch/__init__.py b/aioelasticsearch/__init__.py index ca2f33b3..be00d472 100644 --- a/aioelasticsearch/__init__.py +++ b/aioelasticsearch/__init__.py @@ -1,5 +1,3 @@ -import asyncio - from elasticsearch import Elasticsearch as _Elasticsearch # noqa # isort:skip from elasticsearch.connection_pool import (ConnectionSelector, # noqa # isort:skip RoundRobinSelector) @@ -23,12 +21,8 @@ def __init__( loop=None, **kwargs ): - if loop is None: - loop = asyncio.get_event_loop() - - self.loop = loop - - kwargs['loop'] = self.loop + if loop is not None: + kwargs['loop'] = loop super().__init__(hosts, transport_class=transport_class, **kwargs) diff --git a/aioelasticsearch/connection.py b/aioelasticsearch/connection.py index 570ba280..852b32de 100644 --- a/aioelasticsearch/connection.py +++ b/aioelasticsearch/connection.py @@ -35,7 +35,7 @@ def __init__( maxsize=10, headers=None, *, - loop, + loop=None, **kwargs ): assert not( @@ -50,6 +50,8 @@ def __init__( self.headers = headers self.headers.setdefault('Content-Type', 'application/json') + if loop is None: + loop = asyncio.get_event_loop() self.loop = loop if http_auth is not None: diff --git a/aioelasticsearch/pool.py b/aioelasticsearch/pool.py index 06ec1254..9f4b6f53 100644 --- a/aioelasticsearch/pool.py +++ b/aioelasticsearch/pool.py @@ -20,7 +20,7 @@ def __init__( selector_class=RoundRobinSelector, randomize_hosts=True, *, - loop, + loop=None, **kwargs ): self._dead_timeout = dead_timeout @@ -31,6 +31,8 @@ def __init__( self.dead = asyncio.PriorityQueue(len(self.connections), loop=loop) self.dead_count = collections.Counter() + if loop is None: + loop = asyncio.get_event_loop() self.loop = loop if randomize_hosts: @@ -122,6 +124,8 @@ def __init__(self, connections, *, loop, **kwargs): 'DummyConnectionPool needs exactly one connection defined.', ) + if loop is None: + loop = asyncio.get_event_loop() self.loop = loop self.connection_opts = connections diff --git a/aioelasticsearch/transport.py b/aioelasticsearch/transport.py index 8fe11127..a401a991 100644 --- a/aioelasticsearch/transport.py +++ b/aioelasticsearch/transport.py @@ -1,5 +1,6 @@ import asyncio import logging +import warnings from itertools import chain, count from elasticsearch.serializer import (DEFAULT_SERIALIZERS, Deserializer, @@ -34,9 +35,15 @@ def __init__( retry_on_timeout=False, send_get_body_as='GET', *, - loop, + loop=None, **kwargs ): + if loop is not None: + warnings.warn( + "loop argument is deprecated", DeprecationWarning, stacklevel=2 + ) + else: + loop = asyncio.get_event_loop() self.loop = loop self._closed = False @@ -71,7 +78,7 @@ def __init__( # store all strategies... self.connection_pool_class = connection_pool_class self.connection_class = connection_class - self._connection_pool_lock = asyncio.Lock(loop=self.loop) + self._connection_pool_lock = asyncio.Lock() # ...save kwargs to be passed to the connections self.kwargs = kwargs