Skip to content

Commit e5e71ff

Browse files
committed
io.asyncioreactor: fix deprecated usages for working with python>=3.10
* stop using the loop argument for `asyncio.Lock` and asyncio.Quoue` * on the lock replace `with await` with `async with`, which is the correct syntax for using that lock
1 parent 309aa31 commit e5e71ff

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

cassandra/io/asyncioreactor.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from cassandra.connection import Connection, ConnectionShutdown
2-
2+
import sys
33
import asyncio
44
import logging
55
import os
@@ -89,9 +89,11 @@ def __init__(self, *args, **kwargs):
8989

9090
self._connect_socket()
9191
self._socket.setblocking(0)
92-
93-
self._write_queue = asyncio.Queue(loop=self._loop)
94-
self._write_queue_lock = asyncio.Lock(loop=self._loop)
92+
loop_args = dict()
93+
if sys.version_info[0] == 3 and sys.version_info[1] < 10:
94+
loop_args['loop'] = self._loop
95+
self._write_queue = asyncio.Queue(**loop_args)
96+
self._write_queue_lock = asyncio.Lock(**loop_args)
9597

9698
# see initialize_reactor -- loop is running in a separate thread, so we
9799
# have to use a threadsafe call
@@ -174,7 +176,7 @@ def push(self, data):
174176

175177
async def _push_msg(self, chunks):
176178
# This lock ensures all chunks of a message are sequential in the Queue
177-
with await self._write_queue_lock:
179+
async with self._write_queue_lock:
178180
for chunk in chunks:
179181
self._write_queue.put_nowait(chunk)
180182

0 commit comments

Comments
 (0)