-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adlfs replaces main thread event loop #291
Comments
Hi, I'd like to chip in to the issue to highlight its severity. adlfs behavior brought me some more wrinkles while trying to figure out what is going on. fsspec is creating a loop in subthread which is fine and causes no issues https://github.com/fsspec/filesystem_spec/blob/master/fsspec/asyn.py#L135. However, adlfs when trying to connect https://github.com/fsspec/adlfs/blob/main/adlfs/spec.py#L495 takes this loop which is running in a subthread and set it as loop in the main thread. This cannot work because when main thread wants to work with the loop later and calls
You can see the problem in following example
I should be able to run
So using adlfs prevents later usage of asyncio event loop which I consider a major bug and blocker. |
I've ended up wrapping all calls in this context manager: @contextlib.contextmanager
def wrap_fss():
try:
loop = asyncio.get_event_loop()
except RuntimeError:
loop = None
try:
asyncio.set_event_loop(fsspec.asyn.get_loop())
yield
finally:
asyncio.set_event_loop(loop) |
Thanks for the workaround! |
Thanks for the context. I'm not so familiar with adlfs and fsspec or azure sdk to be able to see all implications. Maybe we could just use the snippet by @Eugeny in #291 (comment): thus when RuntimeError is raised first get the current event loop and then make sure to set it in Just beware that I can see also another problem here
May create an endless recursion if |
Opening an
AzureBlobFile
will swap out the calling thread's event loop for fsspec thread's own event loop. If it's required for Azure SDK that's all nice and good, butadlfs
should clean up after itself.The text was updated successfully, but these errors were encountered: