Using fsspec in flask-socketio views #2098
Unanswered
rob-ashdown-monolith
asked this question in
Q&A
Replies: 1 comment 2 replies
-
This is likely an incompatiblity between the fsspec package and gevent. But I hope you understand that using gevent with Flask-SocketIO is entirely optional. If this combination gives you issues, then I'd suggest you drop gevent and use the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am having problems using fsspec-based filesystems (e.g. adlfs, s3fs) within flask-socketio using gevent.
I'm posting here in the hope that someone has managed to get this working and can offer some guidance.
Whenever I try and call an fspec filesystem method (e.g.
ls
), within a flask/flask-socketio view (sync) it raises the following error:NotImplementedError: Calling sync() from within a running loop
This is to with the way that fsspec wraps its async methods in order that they can be used in sync methods (my view in this case)
minimal example:
server.py
results in
requirements.txt
Info
I have tried various alternatives, to no avail.
e.g.
_ls
(the underlying fsspec async method)asyncio.run(fs._ls)
The issue goes away if I monkeypatch everything but
threads
, but that seems unwise.It is possible to pass a loop to
AzureBlobFileSystem()
but I can't currently get that working either.I can bypass the issue by telling
flask-socketio
to usethreading
and notgevent
(and remove the patching), however this has limitations (i.e. it useswerkzeug
server, which is dev only) which means it can't be used in production. I am working on usinggunicorn
with simple-web-socket in the meantime, but would prefer not to go that rout, if I can in fact get the original usage working.Beta Was this translation helpful? Give feedback.
All reactions