Reduce CPU usage of dev mode (#7113)

* Add code

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Freddy Boulton 2024-01-23 11:32:50 -08:00 committed by GitHub
parent 82fe73d042
commit 28e8a8a3ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Reduce CPU usage of dev mode

View File

@ -10,6 +10,7 @@ from __future__ import annotations
import inspect
import os
import re
import site
import subprocess
import sys
import threading
@ -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():

View File

@ -14,6 +14,7 @@ import os
import pkgutil
import re
import threading
import time
import traceback
import typing
import urllib.parse
@ -223,6 +224,7 @@ def watchfn(reloader: SourceFileReloader):
else:
reloader.swap_blocks(demo)
mtimes = {}
time.sleep(0.05)
def colab_check() -> bool: