|
11 | 11 | from concurrent.futures import ProcessPoolExecutor
|
12 | 12 | import os
|
13 | 13 | from pathlib import Path
|
14 |
| -import subprocess as sp |
| 14 | +import subprocess |
15 | 15 | from tempfile import NamedTemporaryFile
|
16 | 16 | import time
|
17 | 17 | import typing as tp
|
18 | 18 | import warnings
|
| 19 | +from unittest import mock |
19 | 20 |
|
20 | 21 | import torch
|
21 | 22 | import gradio as gr
|
|
32 | 33 | BATCHED_DURATION = 15
|
33 | 34 | INTERRUPTING = False
|
34 | 35 | MBD = None
|
35 |
| -# We have to wrap subprocess call to clean a bit the log when using gr.make_waveform |
36 |
| -_old_call = sp.call |
37 | 36 |
|
38 |
| - |
39 |
| -def _call_nostderr(*args, **kwargs): |
40 |
| - # Avoid ffmpeg vomiting on the logs. |
41 |
| - kwargs['stderr'] = sp.DEVNULL |
42 |
| - kwargs['stdout'] = sp.DEVNULL |
43 |
| - _old_call(*args, **kwargs) |
44 |
| - |
45 |
| - |
46 |
| -sp.call = _call_nostderr |
47 | 37 | # Preallocating the pool of processes.
|
48 | 38 | pool = ProcessPoolExecutor(4)
|
49 | 39 | pool.__enter__()
|
@@ -77,12 +67,20 @@ def _cleanup(self):
|
77 | 67 | file_cleaner = FileCleaner()
|
78 | 68 |
|
79 | 69 |
|
| 70 | +def _call_nostderr(*args, **kwargs): |
| 71 | + # Avoid ffmpeg vomiting on the logs. |
| 72 | + kwargs['stderr'] = subprocess.DEVNULL |
| 73 | + kwargs['stdout'] = subprocess.DEVNULL |
| 74 | + return subprocess.call(*args, **kwargs) |
| 75 | + |
| 76 | + |
80 | 77 | def make_waveform(*args, **kwargs):
|
81 | 78 | # Further remove some warnings.
|
82 | 79 | be = time.time()
|
83 | 80 | with warnings.catch_warnings():
|
84 | 81 | warnings.simplefilter('ignore')
|
85 |
| - out = gr.make_waveform(*args, **kwargs) |
| 82 | + with mock.patch('subprocess.call', _call_nostderr): |
| 83 | + out = gr.make_waveform(*args, **kwargs) |
86 | 84 | print("Make a video took", time.time() - be)
|
87 | 85 | return out
|
88 | 86 |
|
|
0 commit comments