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

Python 3.10 support (loop parameter was removed from Lock()) #916

Closed
SergeiMinaev opened this issue Mar 11, 2021 · 13 comments · Fixed by #936
Closed

Python 3.10 support (loop parameter was removed from Lock()) #916

SergeiMinaev opened this issue Mar 11, 2021 · 13 comments · Fixed by #936

Comments

@SergeiMinaev
Copy link

Hello. I'm trying python 3.10 and it seems like websockets doesn't support it yet.

How to reproduce:
Get a working websockets server and try to run a client with python3.10:

import websockets

async def hello():
    uri = "ws://localhost:8100"
    async with websockets.connect(uri) as websocket:
        await websocket.send('test')
asyncio.get_event_loop().run_until_complete(hello())

This code breaks with such error:

Traceback (most recent call last):
  File "ws_cl.py", line 8, in <module>
    asyncio.get_event_loop().run_until_complete(hello())
  File "/usr/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
    return future.result()
  File "ws_cl.py", line 6, in hello
    async with websockets.connect(uri) as websocket:
  File "venv/lib/python3.10/site-packages/websockets/client.py", line 517, in __aenter__
    return await self
  File "venv/lib/python3.10/site-packages/websockets/client.py", line 535, in __await_impl__
    transport, protocol = await self._create_connection()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1080, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1098, in _create_connection_transport
    protocol = protocol_factory()
  File "venv/lib/python3.10/site-packages/websockets/client.py", line 69, in __init__
    super().__init__(**kwargs)
  File "venv/lib/python3.10/site-packages/websockets/protocol.py", line 235, in __init__
    self._drain_lock = asyncio.Lock(
  File "/usr/lib/python3.10/asyncio/locks.py", line 77, in __init__
    super().__init__(loop=loop)
  File "/usr/lib/python3.10/asyncio/mixins.py", line 17, in __init__
    raise TypeError(
TypeError: As of 3.10, the *loop* parameter was removed from Lock() since it is no longer necessary

I've looked into websockets/protocol.py:235 and there's already exist some check of python version:

self._drain_lock = asyncio.Lock(
    loop=loop if sys.version_info[:2] < (3, 8) else None
)

But from what I understand, this is not enough to solve this problem.

@aaugustin
Copy link
Member

aaugustin commented Mar 12, 2021

We're going to need something like:

self._drain_lock = asyncio.Lock(
    **({"loop": loop} if sys.version_info[:2] < (3, 8) else {})
)

There's a bunch of other instances of this pattern. I can fix them.

@aaugustin
Copy link
Member

Filing #935 for later.

@aaugustin
Copy link
Member

So, the big problem is that Python 3.10 deprecates interacting with a non-running event loop, while websockets entire test suite depends on this pattern :-(

aaugustin added a commit that referenced this issue May 2, 2021
Refs #916 - get_event_loop is deprecated in Python 3.10.

Fix #534.
aaugustin added a commit that referenced this issue May 3, 2021
Refs #916 - get_event_loop is deprecated in Python 3.10.

Fix #534.
@malcovitch
Copy link

Hi. Has this been resolved, yet? I'm trying to use websockets with Python 3.10...

@aaugustin
Copy link
Member

See 5 lines above ;-)

@Nvl977
Copy link

Nvl977 commented Nov 30, 2021

See 5 lines above ;-)

Hi mate, couldnt seem to find the solution, any chance of a direct link? Fairly new to the WSS side. Is it the thread 'Remove the use of get_event_loop'?

Thanks in advance

@aaugustin
Copy link
Member

I was referring to the fact that this issue is fixed and the current version of websockets fully supports Python 3.10.

@Patrickchong95823
Copy link

Hi, I am getting a very similar error when using web sockets to pull Binance API data: "TypeError: As of 3.10, the loop parameter was removed from Queue() since it is no longer necessary". Is there a working solution for the issue? I can't understand the discussion above- from what I gather this is still an ongoing issue?

@Patrickchong95823
Copy link

Patrickchong95823 commented Feb 12, 2022

I was referring to the fact that this issue is fixed and the current version of websockets fully supports Python 3.10.

How do we fix it? I am using Python 3.10 - is there a later version of something I need to install, or ... ?

@aaugustin
Copy link
Member

FYI https://websockets.readthedocs.io/en/stable/project/contributing.html#cryptocurrency-users

@HectorGitt
Copy link

Hi, I am getting a very similar error when using web sockets to pull Binance API data: "TypeError: As of 3.10, the loop parameter was removed from Queue() since it is no longer necessary". Is there a working solution for the issue? I can't understand the discussion above- from what I gather this is still an ongoing issue?

Upgrade package websockets from 9.1 to latest version

@Jessie-1
Copy link

@aaugustin
Copy link
Member

This kind of behavior is exactly why I stopped wasting my time with crypto enthusiasts like you.

@python-websockets python-websockets locked as off-topic and limited conversation to collaborators Oct 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants