Comments (7)
Thanks for the thorough deep dive @gogasca ! I don't think this is a gradio issue since nest-asyncio
is not a dependency of gradio, it's a dependency of jupyter notebook.
I am not sure what is different between enterprise and free colab based on the pip diff.
I will contact someone at google colab to let them know of the problem and I suggest you do the same so they can look into it.
I will close in the meantime! Thank you again.
from gradio.
The minimal repro seems to be running uvicorn in a separate thread with uvloop installed
https://colab.research.google.com/drive/1fHjPNzOJwM9KtPbhHJsNUgJEwpy5rWQP?usp=sharing
from gradio.
Hi @vanessa-bonifaz ! It seems to be an issue with the Colab Enterprise, not Gradio, since Gradio works fine in normal Colab. I would contact their support team.
from gradio.
Facing the same issue in Colab Enterprise, works fine in free Colab.
import gradio as gr
def greet(name):
return "Hello " + name + "!"
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch(share=True, debug=True)
Exception in thread Thread-13 (run):
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.10/dist-packages/uvicorn/server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/local/lib/python3.10/dist-packages/nest_asyncio.py", line 26, in run
loop = asyncio.get_event_loop()
File "/usr/local/lib/python3.10/dist-packages/nest_asyncio.py", line 40, in _get_event_loop
loop = events.get_event_loop_policy().get_event_loop()
File "/usr/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-13 (run)'.
Starting...
127.0.0.1
/usr/lib/python3.10/threading.py:1018: RuntimeWarning: coroutine 'Server.serve' was never awaited
self._invoke_excepthook(self)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Exception in thread Thread-14 (run):
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.10/dist-packages/uvicorn/server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/local/lib/python3.10/dist-packages/nest_asyncio.py", line 26, in run
loop = asyncio.get_event_loop()
File "/usr/local/lib/python3.10/dist-packages/nest_asyncio.py", line 40, in _get_event_loop
loop = events.get_event_loop_policy().get_event_loop()
File "/usr/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-14 (run)'.
Starting...
127.0.0.1
Exception in thread Thread-15 (run):
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.10/dist-packages/uvicorn/server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/local/lib/python3.10/dist-packages/nest_asyncio.py", line 26, in run
loop = asyncio.get_event_loop()
File "/usr/local/lib/python3.10/dist-packages/nest_asyncio.py", line 40, in _get_event_loop
loop = events.get_event_loop_policy().get_event_loop()
File "/usr/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-15 (run)'.
Starting...
127.0.0.1
Exception in thread Thread-16 (run):
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.10/dist-packages/uvicorn/server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/local/lib/python3.10/dist-packages/nest_asyncio.py", line 26, in run
loop = asyncio.get_event_loop()
File "/usr/local/lib/python3.10/dist-packages/nest_asyncio.py", line 40, in _get_event_loop
loop = events.get_event_loop_policy().get_event_loop()
File "/usr/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-16 (run)'.
Starting...
127.0.0.1
Exception in thread Thread-17 (run):
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.10/dist-packages/uvicorn/server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/local/lib/python3.10/dist-packages/nest_asyncio.py", line 26, in run
loop = asyncio.get_event_loop()
File "/usr/local/lib/python3.10/dist-packages/nest_asyncio.py", line 40, in _get_event_loop
loop = events.get_event_loop_policy().get_event_loop()
File "/usr/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-17 (run)'.
Starting...
127.0.0.1
Exception in thread Thread-18 (run):
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.10/dist-packages/uvicorn/server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/local/lib/python3.10/dist-packages/nest_asyncio.py", line 26, in run
loop = asyncio.get_event_loop()
File "/usr/local/lib/python3.10/dist-packages/nest_asyncio.py", line 40, in _get_event_loop
loop = events.get_event_loop_policy().get_event_loop()
File "/usr/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-18 (run)'.
Starting...
127.0.0.1
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
[<ipython-input-1-726b27cae8d1>](https://localhost:8080/#) in <cell line: 12>()
10
11 demo = gr.Interface(fn=greet, inputs="text", outputs="text")
---> 12 demo.launch(share=False, inbrowser=True, debug=True)
2 frames
[/usr/local/lib/python3.10/dist-packages/gradio/blocks.py](https://localhost:8080/#) in launch(self, inline, inbrowser, share, debug, max_threads, auth, auth_message, prevent_thread_lock, show_error, server_name, server_port, height, width, favicon_path, ssl_keyfile, ssl_certfile, ssl_keyfile_password, ssl_verify, quiet, show_api, allowed_paths, blocked_paths, root_path, app_kwargs, state_session_capacity, share_server_address, share_server_protocol, auth_dependency, max_file_size, _frontend)
2215 local_url,
2216 server,
-> 2217 ) = http_server.start_server(
2218 app=self.app,
2219 server_name=server_name,
[/usr/local/lib/python3.10/dist-packages/gradio/http_server.py](https://localhost:8080/#) in start_server(app, server_name, server_port, ssl_keyfile, ssl_certfile, ssl_keyfile_password)
149 )
150 server = Server(config=config, reloader=reloader)
--> 151 server.run_in_thread()
152 break
153 except (OSError, ServerFailedToStartError):
[/usr/local/lib/python3.10/dist-packages/gradio/http_server.py](https://localhost:8080/#) in run_in_thread(self)
57 start = time.time()
58 while not self.started:
---> 59 time.sleep(1e-3)
60 if time.time() - start > 5:
61 raise ServerFailedToStartError(
from gradio.
@freddyaboulton When I try to run the same code in Colab Enterprise Terminal, it works fine. Fails when running the same code inside Notebook.
/content# python
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gradio as gr
>>>
>>> def greet(name):
... return "Hello " + name + "!"
...
>>> demo = gr.Interface(fn=greet, inputs="text", outputs="text")
>>> demo.launch(share=True)
Running on local URL: http://127.0.0.1:7860
Running on public URL: https://e36ae94a0ed51f0f3d.gradio.live
This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)
This is the diff for pip
: https://www.diffchecker.com/J75IJCDz/
I tried a pip freeze > requirements.txt
in Free Colab and then a pip install -r requirements.txt
in Colab Enterprise and same error.
Seems related to https://stackoverflow.com/questions/46727787/runtimeerror-there-is-no-current-event-loop-in-thread-in-async-apscheduler but looking for any insights.
from gradio.
Based on: https://stackoverflow.com/a/46750562/260826
Changed these lines in: /usr/local/lib/python3.10/dist-packages/nest_asyncio.py
and now works.
def _patch_asyncio():
"""Patch asyncio module to use pure Python tasks and futures."""
def run(main, *, debug=False):
# loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
Not sure what may be the root cause.
from gradio.
Seems related:
#5941
Another workaround is to do pip uninstall uvloop
.
from gradio.
Related Issues (20)
- Customize the examples in ChatInterface
- Panning/zooming for Model3D viewer is broken is some cases
- Absolute paths are not working for images mount_gradio_app HOT 2
- CURL/requests documentation to swagger docs HOT 2
- Vertical spacing issue of `gr.DuplicateButton` HOT 4
- Allow users to change the chatbot area HOT 1
- Delete callback in gr.State is not called on reload or tab close HOT 2
- API Recorder not working for HuggingFace space HOT 2
- Audio path none on longer audio recording
- ERROR: Exception in ASGI application when input image streaming = True HOT 1
- 4.28.0 and later -- breaking change so components being updated in queued function calls are not interactable HOT 4
- Add auto-scroll down to the bottom of the Gradio chat box whenever there's a new LLM response or show down arrow button HOT 1
- Accordion label is not displayed when theme is set to monochrome
- Cannot connect to SSE endpoint HOT 3
- Be able to pass the component loader to each svelte component HOT 1
- API recorder broken on several demos HOT 2
- IsADirectoryError: [Errno 21] Is a directory: '/xxx' HOT 4
- Successful use of gradio SSE with private hf space, but inference causes error client side HOT 5
- Add option to use default <audio> tag HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gradio.