Skip to content

Commit 174f707

Browse files
committed
Remove event loop parameter
1 parent 9537532 commit 174f707

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +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>=9.1,<11",
93+
"websockets>=10.0.0,<11",
9494
],
9595
python_requires='>=3.7,<3.10',
9696
extras_require=extras_require,

tests/core/providers/test_websocket_provider.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ 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+
41+
asyncio.set_event_loop(event_loop)
42+
server = websockets.serve(empty_server, '127.0.0.1', open_port)
4143
event_loop.run_until_complete(server)
4244
event_loop.run_forever()
4345

@@ -54,7 +56,7 @@ def w3(open_port, start_websocket_server):
5456
# need new event loop as the one used by server is already running
5557
event_loop = asyncio.new_event_loop()
5658
endpoint_uri = 'ws://127.0.0.1:{}'.format(open_port)
57-
event_loop.run_until_complete(wait_for_ws(endpoint_uri, event_loop))
59+
event_loop.run_until_complete(wait_for_ws(endpoint_uri))
5860
provider = WebsocketProvider(endpoint_uri, websocket_timeout=0.01)
5961
return Web3(provider)
6062

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=10):
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

0 commit comments

Comments
 (0)