Skip to content

Commit 0f301c0

Browse files
committed
Remove event loop parameter
1 parent 3579094 commit 0f301c0

File tree

6 files changed

+12
-14
lines changed

6 files changed

+12
-14
lines changed

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@
9090
"requests>=2.16.0,<3.0.0",
9191
# remove typing_extensions after python_requires>=3.8, see web3._utils.compat
9292
"typing-extensions>=3.7.4.1,<5;python_version<'3.8'",
93-
# websockets 10.0 removed support for python 3.6.
94-
# We can remove this line once we drop 3.6 support as well
95-
"websockets>=9.1,<10;python_version<'3.7'",
96-
"websockets>=9.1,<11;python_version>'3.6'",
93+
"websockets>=10.0.0,<11",
9794
],
9895
python_requires='>=3.6,<4',
9996
extras_require=extras_require,

tests/core/providers/test_websocket_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def empty_server(websocket, path):
3737
data = await websocket.recv()
3838
await asyncio.sleep(0.02)
3939
await websocket.send(data)
40-
server = websockets.serve(empty_server, '127.0.0.1', open_port, loop=event_loop)
40+
server = websockets.serve(empty_server, '127.0.0.1', open_port)
4141
event_loop.run_until_complete(server)
4242
event_loop.run_forever()
4343

tests/integration/go_ethereum/test_goethereum_ws.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import pytest
23

34
from tests.integration.common import (
@@ -63,8 +64,9 @@ def geth_command_arguments(geth_binary,
6364

6465

6566
@pytest.fixture(scope="module")
66-
def web3(geth_process, endpoint_uri, event_loop):
67-
event_loop.run_until_complete(wait_for_ws(endpoint_uri, event_loop))
67+
def web3(geth_process, endpoint_uri):
68+
event_loop = asyncio.new_event_loop()
69+
event_loop.run_until_complete(wait_for_ws(endpoint_uri))
6870
_web3 = Web3(Web3.WebsocketProvider(endpoint_uri, websocket_timeout=30))
6971
return _web3
7072

tests/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ def get_open_port():
1313
return str(port)
1414

1515

16-
async def wait_for_ws(endpoint_uri, event_loop, timeout=60):
16+
async def wait_for_ws(endpoint_uri, timeout=60):
1717
start = time.time()
1818
while time.time() < start + timeout:
1919
try:
20-
async with websockets.connect(uri=endpoint_uri, loop=event_loop):
20+
async with websockets.connect(uri=endpoint_uri):
2121
pass
2222
except (ConnectionRefusedError, OSError):
2323
await asyncio.sleep(0.01)

web3/providers/websocket.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,16 @@ def get_default_endpoint() -> URI:
6060
class PersistentWebSocket:
6161

6262
def __init__(
63-
self, endpoint_uri: URI, loop: asyncio.AbstractEventLoop, websocket_kwargs: Any
63+
self, endpoint_uri: URI, websocket_kwargs: Any
6464
) -> None:
6565
self.ws: WebSocketClientProtocol = None
6666
self.endpoint_uri = endpoint_uri
67-
self.loop = loop
6867
self.websocket_kwargs = websocket_kwargs
6968

7069
async def __aenter__(self) -> WebSocketClientProtocol:
7170
if self.ws is None:
7271
self.ws = await connect(
73-
uri=self.endpoint_uri, loop=self.loop, **self.websocket_kwargs
72+
uri=self.endpoint_uri, **self.websocket_kwargs
7473
)
7574
return self.ws
7675

@@ -113,7 +112,7 @@ def __init__(
113112
'found: {1}'.format(RESTRICTED_WEBSOCKET_KWARGS, found_restricted_keys)
114113
)
115114
self.conn = PersistentWebSocket(
116-
self.endpoint_uri, WebsocketProvider._loop, websocket_kwargs
115+
self.endpoint_uri, websocket_kwargs
117116
)
118117
super().__init__()
119118

web3/tools/benchmark/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def main(logger: logging.Logger, num_calls: int) -> None:
120120
for built_fixture in fixture.build():
121121
for process in built_fixture:
122122
w3_http = build_web3_http(fixture.endpoint_uri)
123-
loop = asyncio.get_event_loop()
123+
loop = asyncio.get_running_loop()
124124
async_w3_http = loop.run_until_complete(build_async_w3_http(fixture.endpoint_uri))
125125
# TODO: swap out w3_http for the async_w3_http once GethPersonal module is async
126126
async_unlocked_acct = loop.run_until_complete(

0 commit comments

Comments
 (0)