Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:AUTOMATIC1111 Stable diffusion webui Call Queue

From Leeroopedia


Knowledge Sources
Domains Concurrency, Gradio_Integration
Last Updated 2025-05-15 00:00 GMT

Overview

Provides decorator-based wrappers that serialize Gradio UI calls through a FIFO lock, managing GPU task queuing, error handling, and performance statistics.

Description

The Call Queue module implements a set of function decorators used to wrap Gradio callback functions so that they execute sequentially through a shared FIFO lock. This prevents concurrent GPU operations from interfering with each other. The module provides three levels of wrapping: wrap_queued_call for basic serialization, wrap_gradio_gpu_call for GPU-intensive operations with full task lifecycle management (queuing, progress tracking, result recording), and wrap_gradio_call/wrap_gradio_call_no_job for general Gradio calls with error handling and optional performance statistics. The performance stats include elapsed time, VRAM usage (active peak, reserved peak, system peak), and optional profiling data appended as HTML to the response.

Usage

Use these wrappers when registering Gradio UI event handlers that trigger image generation or other GPU-intensive operations. wrap_gradio_gpu_call is the primary wrapper for generation tasks, while wrap_gradio_call is used for lighter operations that still need error handling and state cleanup.

Code Reference

Source Location

Signature

def wrap_queued_call(func) -> callable
def wrap_gradio_gpu_call(func, extra_outputs=None) -> callable
def wrap_gradio_call(func, extra_outputs=None, add_stats=False) -> callable
def wrap_gradio_call_no_job(func, extra_outputs=None, add_stats=False) -> callable

Import

from modules.call_queue import wrap_gradio_gpu_call, wrap_gradio_call, wrap_queued_call

I/O Contract

Inputs

Name Type Required Description
func callable Yes The Gradio callback function to wrap
extra_outputs list or None No Default outputs to return in case of an error
add_stats bool No Whether to append performance statistics HTML to the last output element

Outputs

Name Type Description
wrapped_func callable A decorated function that serializes execution through the FIFO lock and adds error handling

Usage Examples

from modules.call_queue import wrap_gradio_gpu_call, wrap_gradio_call

# Wrap a GPU-intensive generation function
def generate_images(task_id, prompt, steps):
    # ... generation logic ...
    return [image, info, html_status]

wrapped_generate = wrap_gradio_gpu_call(generate_images, extra_outputs=[None, ""])

# Wrap a lighter Gradio callback
def apply_settings(*args):
    # ... settings logic ...
    return [result, status_html]

wrapped_settings = wrap_gradio_call(apply_settings)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment