Skip to content

Commit 2be6aaa

Browse files
authored
Better way to support Python 3.10 for ensure_future (#277)
1 parent c7d65c7 commit 2be6aaa

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

gql/client.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,9 @@ def subscribe(
220220
# Note: we need to create a task here in order to be able to close
221221
# the async generator properly on python 3.8
222222
# See https://bugs.python.org/issue38559
223-
with warnings.catch_warnings():
224-
warnings.filterwarnings(
225-
"ignore", message="There is no current event loop"
226-
)
227-
generator_task = asyncio.ensure_future(async_generator.__anext__())
223+
generator_task = asyncio.ensure_future(
224+
async_generator.__anext__(), loop=loop
225+
)
228226
result = loop.run_until_complete(generator_task)
229227
yield result
230228

tests/test_websocket_subscription.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ def test_websocket_subscription_sync_graceful_shutdown(server, subscription_str)
521521
count = 10
522522
subscription = gql(subscription_str.format(count=count))
523523

524+
interrupt_task = None
525+
524526
with pytest.raises(KeyboardInterrupt):
525527
for result in client.subscribe(subscription):
526528

@@ -536,14 +538,17 @@ def test_websocket_subscription_sync_graceful_shutdown(server, subscription_str)
536538
warnings.filterwarnings(
537539
"ignore", message="There is no current event loop"
538540
)
539-
asyncio.ensure_future(
541+
interrupt_task = asyncio.ensure_future(
540542
client.session._generator.athrow(KeyboardInterrupt)
541543
)
542544

543545
count -= 1
544546

545547
assert count == 4
546548

549+
# Catch interrupt_task exception to remove warning
550+
interrupt_task.exception()
551+
547552
# Check that the server received a connection_terminate message last
548553
assert logged_messages.pop() == '{"type": "connection_terminate"}'
549554

0 commit comments

Comments
 (0)