[Refactoring] Convert async functions that don't contain await statements to normal functions (#5677)

* [Refactoring] Convert async functions that don't contain `await` statements to normal functions

* add changeset

* add changeset

* fix tests

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
Yuichiro Tachibana (Tsuchiya) 2023-09-26 04:58:01 +08:00 committed by GitHub
parent c5e9695596
commit 9f9af327c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 10 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
feat:[Refactoring] Convert async functions that don't contain `await` statements to normal functions

View File

@ -1553,7 +1553,7 @@ Received outputs:
"average_duration": block_fn.total_runtime / block_fn.total_runs,
}
async def create_limiter(self):
def create_limiter(self):
self.limiter = (
None
if self.max_threads == 40
@ -2344,10 +2344,10 @@ Received outputs:
"""Events that should be run when the app containing this block starts up."""
if self.enable_queue:
utils.run_coro_in_background(self._queue.start, self.ssl_verify)
self._queue.start()
# So that processing can resume in case the queue was stopped
self._queue.stopped = False
utils.run_coro_in_background(self.create_limiter)
self.create_limiter()
def queue_enabled_for_fn(self, fn_index: int):
if self.dependencies[fn_index]["queue"] is None:

View File

@ -76,7 +76,7 @@ class Queue:
self.blocks_dependencies = blocks_dependencies
self.continuous_tasks: list[Event] = []
async def start(self, ssl_verify=True):
def start(self):
run_coro_in_background(self.start_processing)
run_coro_in_background(self.start_log_and_progress_updates)
if not self.live_updates:

View File

@ -36,15 +36,13 @@ def mock_event() -> Event:
class TestQueueMethods:
@pytest.mark.asyncio
async def test_start(self, queue: Queue):
await queue.start()
def test_start(self, queue: Queue):
queue.start()
assert queue.stopped is False
assert queue.get_active_worker_count() == 0
@pytest.mark.asyncio
async def test_stop_resume(self, queue: Queue):
await queue.start()
def test_stop_resume(self, queue: Queue):
queue.start()
queue.close()
assert queue.stopped
queue.resume()