Skip to content
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

NiceGUI uses 100% of a CPU core when running inside a container #3066

Open
rodja opened this issue May 13, 2024 Discussed in #2998 · 1 comment
Open

NiceGUI uses 100% of a CPU core when running inside a container #3066

rodja opened this issue May 13, 2024 Discussed in #2998 · 1 comment
Labels
bug Something isn't working

Comments

@rodja
Copy link
Member

rodja commented May 13, 2024

Discussed in #2998

Originally posted by pwt May 1, 2024

Question

Hi folks:

I'm making productive use of NiceGUI and finding it very elegant to use. However, I've run into an issue when trying to deploy an app within a container.

I'm sure I'm doing something dumb here, and I'm hoping someone can point out what. Ideas welcome!

Problem

When I start a NiceGUI app within a container, it will use 100% of a CPU core. I've simplified my setup as far as I can in an attempt to narrow down what the issue could be, as follows:

Dockerfile

FROM python:3.12-slim
RUN pip install --root-user-action=ignore --disable-pip-version-check --no-cache-dir nicegui
COPY nicegui-test.py nicegui-test.py
CMD python nicegui-test.py

NiceGUI App: nicegui-test.py

from nicegui import ui
ui.label('Hello NiceGUI!')
ui.run()

Build the Container Image

docker build -t nicegui-test .

Run the Container

% docker run --rm -p 8080:8080 --name nicegui-run nicegui-test
NiceGUI ready to go on http://localhost:8080, and http://172.17.0.2:8080

This works, but uses a continuous 100% of a CPU core.

Run the NiceGUI App from Bash within a Container

I see the same issue if I start the NiceGUI app from a Bash shell within the container:

% docker run -it --rm -p 8080:8080 --name nicegui-run nicegui-test bash
root@d589ccb0d5d3:/# python nicegui-test.py
NiceGUI ready to go on http://localhost:8080, and http://172.17.0.2:8080

The CPU will latch at 100% once the app is started.

Thanks for any pointers, folks.

Stack Trace

Edit: added stack trace when the app is interrupted:

NiceGUI ready to go on http://localhost:8080, and http://172.17.0.2:8080
^CProcess SpawnProcess-1:
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/usr/local/lib/python3.12/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.12/site-packages/uvicorn/_subprocess.py", line 78, in subprocess_started
    target(sockets=sockets)
  File "/usr/local/lib/python3.12/site-packages/nicegui/server.py", line 36, in run
    super().run(sockets=sockets)
  File "/usr/local/lib/python3.12/site-packages/uvicorn/server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 123, in run
    raise KeyboardInterrupt()
KeyboardInterrupt
```</div>
@rodja rodja added the bug Something isn't working label May 13, 2024
@pwt
Copy link

pwt commented May 15, 2024

Thanks for converting this into an issue.

It looks like using ui.run(reload=False) fixes the issue, which is actually fine for my purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants