Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
python -m pip install -e .

- name: Test
timeout-minutes: 1
run: python -m pytest --cov-report=xml --cov=.

- name: Upload coverage to Codecov
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pytest
pytest-asyncio
pytest-cov
mock-ssh-server
mock-ssh-server @ git+https://github.com/skshetry/mock-ssh-server.git@command-queue-race
importlib-metadata >= 6.0.0
42 changes: 31 additions & 11 deletions sshfs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

import asyncssh
from asyncssh.sftp import SFTPOpUnsupported
from fsspec.asyn import AsyncFileSystem, async_methods, sync, sync_wrapper
from fsspec.asyn import (
AsyncFileSystem,
FSTimeoutError,
async_methods,
sync,
sync_wrapper,
)
from fsspec.utils import infer_storage_options

from sshfs.file import SSHFile
Expand Down Expand Up @@ -71,7 +77,7 @@ def __init__(
**_client_args,
)
weakref.finalize(
self, sync, self.loop, self._finalize, self._pool, self._stack
self, self._finalize, self.loop, self._pool, self._stack
)

@classmethod
Expand Down Expand Up @@ -101,15 +107,29 @@ async def _connect(
connect = sync_wrapper(_connect)

@staticmethod
async def _finalize(pool, stack):
await pool.close()

# If an error occurs while the SSHFile is trying to
# open the native file, then the client might get broken
# due to partial initialization. We are just going to ignore
# the errors that arises on the finalization layer
with suppress(BrokenPipeError):
await stack.aclose()
def _finalize(loop, pool, stack):
async def close():
await pool.close()
# If an error occurs while the SSHFile is trying to
# open the native file, then the client might get broken
# due to partial initialization. We are just going to ignore
# the errors that arises on the finalization layer
with suppress(BrokenPipeError):
await stack.aclose()

if loop is not None and loop.is_running():
try:
loop = asyncio.get_running_loop()
loop.create_task(close())
return
except RuntimeError:
pass

try:
sync(loop, close, timeout=0.1)
return
except FSTimeoutError:
pass

@property
def client(self):
Expand Down
Loading