Skip to content

Commit

Permalink
Reduce CPU usage of dev mode (#7113)
Browse files Browse the repository at this point in the history
* Add code

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
freddyaboulton and gradio-pr-bot committed Jan 23, 2024
1 parent 82fe73d commit 28e8a8a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/petite-islands-follow.md
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Reduce CPU usage of dev mode
12 changes: 9 additions & 3 deletions gradio/cli/commands/reload.py
Expand Up @@ -10,6 +10,7 @@
import inspect
import os
import re
import site
import subprocess
import sys
import threading
Expand Down Expand Up @@ -63,9 +64,14 @@ def _setup_config(

watching_dirs = []
if str(gradio_folder).strip():
watching_dirs.append(gradio_folder)
message += f" '{gradio_folder}'"
message_change_count += 1
package_install = any(
utils.is_in_or_equal(gradio_folder, d) for d in site.getsitepackages()
)
if not package_install:
# This is a source install
watching_dirs.append(gradio_folder)
message += f" '{gradio_folder}'"
message_change_count += 1

abs_parent = abs_original_path.parent
if str(abs_parent).strip():
Expand Down
2 changes: 2 additions & 0 deletions gradio/utils.py
Expand Up @@ -14,6 +14,7 @@
import pkgutil
import re
import threading
import time
import traceback
import typing
import urllib.parse
Expand Down Expand Up @@ -223,6 +224,7 @@ def iter_py_files() -> Iterator[Path]:
else:
reloader.swap_blocks(demo)
mtimes = {}
time.sleep(0.05)


def colab_check() -> bool:
Expand Down

0 comments on commit 28e8a8a

Please sign in to comment.