Preventing GUI Freezes in an LLM-Generated Batch Audio Extraction Tool

    This article examines how to evaluate an LLM’s engineering capability by asking it to generate a desktop tool that batch-extracts audio from video files. It covers runtime environment specification, observed model output, thread-based GUI responsiveness, cross-thread communication, follow-up questions for code understanding, and practical validation steps. Readers can use these points to review generated code and reduce responsiveness and runtime risks in similar tools.

    Preventing GUI Freezes in an LLM-Generated Batch Audio Extraction Tool

    1. Why Use This Requirement as a Test

    Many people evaluate LLM-generated code only by whether the model can write a small runnable function. That test is too simple to reflect engineering capability. A better indicator is a small tool with a GUI, background tasks, and error prompts. This article uses a desktop program that batch-extracts audio from video as a sample. It covers common requirements such as file lists, format selection, progress display, error prompts, and exit control.

    This requirement includes four types of requirements. First, functionality must be complete: support common video formats as input, export audio formats such as MP3 and WAV, support batch import, allow input and output formats to be set, and support starting conversion and exiting the program. Second, the interface must be clear: reasonable layout and clearly separated functional panels. Third, status must be visible: a progress bar and status bar are needed, and prompts should appear when conversion fails or an operation is invalid. Fourth, performance must be stable: the interface must not freeze or become unresponsive during batch conversion.

    2. Confirm the Runtime Environment Before Coding

    Before prompting, you should write the environment into the requirements. Otherwise, the model will assume a default environment, which may be completely different from your machine. Consider specifying the following:

    1. Operating system: Windows, macOS, or Linux. The three differ significantly in paths, permissions, and dependency installation.
    2. GUI framework and version: for example, PyQt, PySide, or Tkinter, with the version number.
    3. Codec tool: a common approach is to call the FFmpeg command-line program. State whether it is already installed and where the program should look for it.
    4. File permissions: whether the output directory is writable and whether the program has permission to read source files.

    The more specific the environment description, the higher the likelihood that generated code will run. The model cannot see your machine and can only infer from common cases.

    3. Model Performance in This Test

    In this test, the code generated by the model in one pass had no obvious syntax errors, and variable definitions were basically complete. However, this conclusion is limited to this prompt and test environment. It does not mean the code will run correctly on all machines, nor does it mean runtime exceptions, missing dependencies, and special inputs have been properly handled. The code still requires manual review and real-file testing.

    The model also proactively added several engineering details.

    First, recursive directory import. When the user selects a folder, the program adds media files in subfolders to the list as well. This feature is useful, but it is necessary to confirm whether the recursion scope and file type filtering are correct.

    Second, same-name file protection. If a file with the same name already exists in the output directory, the program appends a number to the file name, such as audio_1.mp3 or audio_2.mp3, so the original file is not overwritten. It is necessary to confirm the numbering upper limit and how exhaustion is handled. In this test, these rules were not clearly documented in the code documentation; the model should be asked to document them, or they should be defined directly in the code.

    Third, dependency detection. At startup, the program checks whether FFmpeg is available. If it cannot be found, it shows a prompt explaining how to install it rather than exiting with an error. This helps reduce user confusion, but it only covers cases the developer anticipated.

    These behaviors show that the model proactively considers edge cases. However, this is only an observation from one sample and is not enough to prove that it has stable engineering judgment across all tasks.

    4. Core Difficulty: Why the GUI Freezes

    A GUI program usually has only one main thread. This thread draws the interface, responds to button clicks, and handles mouse and keyboard events. If a time-consuming operation such as video conversion is placed directly on the main thread, the main thread will be occupied. During that time, the interface cannot redraw, buttons cannot respond, and the system may mark the program as unresponsive.

    The solution is to assign time-consuming tasks to a worker thread and let the main thread handle only the interface. Each time the worker completes a file, it sends progress information to the main thread, and the main thread updates the progress bar. The key is communication between threads. The worker thread should not directly modify interface widgets; otherwise, race conditions may occur, causing interface corruption at best and program crashes at worst. Common communication approaches include the following three:

    1. Qt signal/slot: in PyQt or PySide, signals can be sent safely across threads.
    2. Thread-safe queue: the worker thread puts messages into a queue, and the main thread reads them periodically.
    3. Callback plus event dispatch: for example, in Tkinter, update the interface in the main thread through the after mechanism.

    The following pseudo-code illustrates the structure. It cannot run directly.

    1. class ExtractionWorker:
    2. signal progress(percent)
    3. signal error(message)
    4. signal finished()
    5. def __init__(self, file_list, output_format):
    6. self.file_list = file_list
    7. self.output_format = output_format
    8. self.cancel_requested = false
    9. def run():
    10. total = length(self.file_list)
    11. for index, file in enumerate(self.file_list):
    12. if self.cancel_requested:
    13. break
    14. try:
    15. extract_audio(file, self.output_format)
    16. except Exception as e:
    17. emit error(f"{file} conversion failed: {e}")
    18. continue
    19. emit progress((index + 1) / total * 100)
    20. emit finished()
    21. # In the main thread
    22. worker = ExtractionWorker(files, "mp3")
    23. worker.progress.connect(progress_bar.setValue)
    24. worker.error.connect(show_message_box)
    25. worker.finished.connect(on_done)
    26. worker.start()

    Several points in this pseudo-code require attention.

    • Signals should be connected to interface functions in the main thread. The worker thread does not call interface widgets directly.
    • When a single file fails, the program should record the error and continue processing later files rather than aborting the whole batch. The specific strategy should be confirmed with the requirements owner.
    • Cancellation is implemented through a flag, which the worker thread checks at appropriate times. You must not forcibly terminate the thread; otherwise, partial files may be left behind.
    • If extract_audio calls an FFmpeg subprocess, Python’s global interpreter lock is usually not a bottleneck because the main cost is in the external process. However, the subprocess error output must be read; otherwise, the child process may block after the output buffer fills.

    5. Use Follow-Up Questions to Test the Model’s Understanding of the Code

    After code generation, follow-up questions should be used to check whether the model truly understands the code it wrote. In this test, someone asked about the default output path. The model answered that, by default, output files are saved in the directory where the source file is located. If the user specifies an output directory in settings, that directory takes priority. If the directory does not exist, the program attempts to create it automatically.

    This answer is consistent with the code logic but still requires manual verification. You can continue with questions such as:

    1. What happens when the output directory does not have write permission?
    2. If the user clicks cancel, will the file currently being converted leave an incomplete file?
    3. If some files fail in a batch task, can the failed files be retried individually?
    4. How does the program handle a source file that is deleted or moved during conversion?
    5. When same-name numbering exceeds the upper limit, does the program stop or skip?

    A good answer will describe specific behavior and point to the corresponding location in the code. If the model gives only a vague description, its understanding of the code is not deep enough, and the developer needs to read the code to confirm.

    6. Conclusion

    This test shows that, when generating code for a relatively complex desktop tool, an LLM can cover most explicit requirements and provide reasonable additions in areas such as directory import, same-name protection, and dependency detection. In this sample, it produced no obvious syntax errors, but that does not mean the code is ready for production. Runtime exceptions, dependency version differences, and special file formats still require real testing.

    For developers, a practical approach has four steps: specify the environment and boundaries in the prompt; ask the model to explain key logic; put time-consuming tasks into worker threads; and run batch tests with real files. These steps may reduce rework time, although the actual effect still needs to be evaluated in the context of the project.