Skip to content

Commit 01ecda4

Browse files
authored
Remove use of asyncio API deprecated in python 3.14 (#1862)
* replace deprecated asyncio.iscoroutinefunction with inspect
1 parent 26f1ea7 commit 01ecda4

File tree

3 files changed

+2
-36
lines changed

3 files changed

+2
-36
lines changed

fsspec/asyn.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import os
88
import re
99
import threading
10-
from contextlib import contextmanager
1110
from glob import has_magic
1211
from typing import TYPE_CHECKING, Iterable
1312

@@ -120,18 +119,6 @@ def wrapper(*args, **kwargs):
120119
return wrapper
121120

122121

123-
@contextmanager
124-
def _selector_policy():
125-
original_policy = asyncio.get_event_loop_policy()
126-
try:
127-
if os.name == "nt" and hasattr(asyncio, "WindowsSelectorEventLoopPolicy"):
128-
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
129-
130-
yield
131-
finally:
132-
asyncio.set_event_loop_policy(original_policy)
133-
134-
135122
def get_loop():
136123
"""Create or return the default fsspec IO loop
137124
@@ -142,8 +129,7 @@ def get_loop():
142129
# repeat the check just in case the loop got filled between the
143130
# previous two calls from another thread
144131
if loop[0] is None:
145-
with _selector_policy():
146-
loop[0] = asyncio.new_event_loop()
132+
loop[0] = asyncio.new_event_loop()
147133
th = threading.Thread(target=loop[0].run_forever, name="fsspecIO")
148134
th.daemon = True
149135
th.start()

fsspec/implementations/asyn_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _wrap_all_sync_methods(self):
8282
continue
8383

8484
method = getattr(self.sync_fs, method_name)
85-
if callable(method) and not asyncio.iscoroutinefunction(method):
85+
if callable(method) and not inspect.iscoroutinefunction(method):
8686
async_method = async_wrapper(method, obj=self)
8787
setattr(self, f"_{method_name}", async_method)
8888

fsspec/tests/test_async.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22
import inspect
33
import io
4-
import os
54
import time
65

76
import pytest
@@ -131,25 +130,6 @@ async def main(**kwargs):
131130
assert sum(asyncio.run(main())) == 32 # override
132131

133132

134-
@pytest.mark.skipif(os.name != "nt", reason="only for windows")
135-
def test_windows_policy():
136-
from asyncio.windows_events import SelectorEventLoop
137-
138-
loop = fsspec.asyn.get_loop()
139-
policy = asyncio.get_event_loop_policy()
140-
141-
# Ensure that the created loop always uses selector policy
142-
assert isinstance(loop, SelectorEventLoop)
143-
144-
# Ensure that the global policy is not changed and it is
145-
# set to the default one. This is important since the
146-
# get_loop() method will temporarily override the policy
147-
# with the one which uses selectors on windows, so this
148-
# check ensures that we are restoring the old policy back
149-
# after our change.
150-
assert isinstance(policy, asyncio.DefaultEventLoopPolicy)
151-
152-
153133
def test_running_async():
154134
assert not fsspec.asyn.running_async()
155135

0 commit comments

Comments
 (0)