Skip to content

Commit c89d7fa

Browse files
committed
Convert async fns to coroutines
1 parent 7211223 commit c89d7fa

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

cassandra/io/asyncioreactor.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010

1111
log = logging.getLogger(__name__)
1212

13-
14-
# This module uses ``yield from`` and ``@asyncio.coroutine`` over ``await`` and
15-
# ``async def`` for pre-Python-3.5 compatibility, so keep in mind that the
16-
# managed coroutines are generator-based, not native coroutines. See PEP 492:
17-
# https://www.python.org/dev/peps/pep-0492/#coroutine-objects
18-
19-
2013
try:
2114
asyncio.run_coroutine_threadsafe
2215
except AttributeError:
@@ -40,9 +33,10 @@ def end(self):
4033
'does not implement .end()')
4134

4235
def __init__(self, timeout, callback, loop):
43-
delayed = self._call_delayed_coro(timeout=timeout,
36+
delayed = asyncio.wait_for(self._call_delayed_coro(timeout=timeout,
4437
callback=callback,
45-
loop=loop)
38+
loop=loop),
39+
timeout=None)
4640
self._handle = asyncio.run_coroutine_threadsafe(delayed, loop=loop)
4741

4842
@staticmethod
@@ -96,10 +90,10 @@ def __init__(self, *args, **kwargs):
9690
# see initialize_reactor -- loop is running in a separate thread, so we
9791
# have to use a threadsafe call
9892
self._read_watcher = asyncio.run_coroutine_threadsafe(
99-
self.handle_read(), loop=self._loop
93+
asyncio.wait_for(self.handle_read(), timeout=None), loop=self._loop
10094
)
10195
self._write_watcher = asyncio.run_coroutine_threadsafe(
102-
self.handle_write(), loop=self._loop
96+
asyncio.wait_for(self.handle_write(), timeout=None), loop=self._loop
10397
)
10498
self._send_options_message()
10599

@@ -132,7 +126,7 @@ def close(self):
132126
# close from the loop thread to avoid races when removing file
133127
# descriptors
134128
asyncio.run_coroutine_threadsafe(
135-
self._close(), loop=self._loop
129+
asyncio.wait_for(self._close(), timeout=None), loop=self._loop
136130
)
137131

138132
async def _close(self):
@@ -165,7 +159,7 @@ def push(self, data):
165159

166160
if self._loop_thread.ident != get_ident():
167161
asyncio.run_coroutine_threadsafe(
168-
self._push_msg(chunks),
162+
asyncio.wait_for(self._push_msg(chunks), timeout=None),
169163
loop=self._loop
170164
)
171165
else:

0 commit comments

Comments
 (0)