Giter VIP home page Giter VIP logo

Comments (7)

freddyaboulton avatar freddyaboulton commented on May 28, 2024 1

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.

freddyaboulton avatar freddyaboulton commented on May 28, 2024 1

The minimal repro seems to be running uvicorn in a separate thread with uvloop installed

https://colab.research.google.com/drive/1fHjPNzOJwM9KtPbhHJsNUgJEwpy5rWQP?usp=sharing

image

from gradio.

freddyaboulton avatar freddyaboulton commented on May 28, 2024

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.

gogasca avatar gogasca commented on May 28, 2024

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.

gogasca avatar gogasca commented on May 28, 2024

@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.

gogasca avatar gogasca commented on May 28, 2024

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.

image

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.

gogasca avatar gogasca commented on May 28, 2024

Seems related:
#5941
Another workaround is to do pip uninstall uvloop.

from gradio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.