Skip to content

Commit

Permalink
Clean up fsspec.py now that Python 3.8 was dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed Nov 7, 2024
1 parent 782f1dd commit 0778497
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions src/uproot/source/fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,10 @@ def chunks(
self._num_requested_chunks += len(ranges)
self._num_requested_bytes += sum(stop - start for start, stop in ranges)

try:
# not available in python 3.8
to_thread = asyncio.to_thread
except AttributeError:
import contextvars
import functools

async def to_thread(func, /, *args, **kwargs):
loop = asyncio.get_running_loop()
ctx = contextvars.copy_context()
func_call = functools.partial(ctx.run, func, *args, **kwargs)
return await loop.run_in_executor(None, func_call)

async def async_wrapper_thread(blocking_func, *args, **kwargs):
if not callable(blocking_func):
raise TypeError("blocking_func must be callable")
# TODO: when python 3.8 is dropped, use `asyncio.to_thread` instead (also remove the try/except block above)
return await to_thread(blocking_func, *args, **kwargs)
return await asyncio.to_thread(blocking_func, *args, **kwargs)

def submit(request_ranges: list[tuple[int, int]]):
paths = [self._file_path] * len(request_ranges)
Expand Down

0 comments on commit 0778497

Please sign in to comment.