Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate loop argument #283

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions aioelasticsearch/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion aioelasticsearch/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
maxsize=10,
headers=None,
*,
loop,
loop=None,
**kwargs
):
assert not(
Expand All @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion aioelasticsearch/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(
selector_class=RoundRobinSelector,
randomize_hosts=True,
*,
loop,
loop=None,
**kwargs
):
self._dead_timeout = dead_timeout
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions aioelasticsearch/transport.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import logging
import warnings
from itertools import chain, count

from elasticsearch.serializer import (DEFAULT_SERIALIZERS, Deserializer,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down