Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffmpeg: pass -nostdin to not alter the terminal settings to begin with. #164

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

rgonzalezfluendo
Copy link
Contributor

Fix issue with Bash Linux terminal does not echo the input characters after running a full test suite.

Thanks to Kerin Millar for the help in the bash list [1]

The issue could be reproduced with

from multiprocessing import Pool
from unittest.result import TestResult
from time import perf_counter
import subprocess

jobs=3
failfast=False
timeout=30
verbose=True
tests = [1,2,3]

def run_command(command, verbose = False, check = True, timeout = None):
    """Runs a command"""
    sout = subprocess.DEVNULL if not verbose else None
    serr = subprocess.DEVNULL if not verbose else None
    if verbose:
        print(f'\nRunning command "{" ".join(command)}"')
    try:
        subprocess.run(command, stdout=sout, stderr=serr, check=check, timeout=timeout)
    except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as ex:
        raise ex

def _run_worker(test):
    print("running", test)
    cmd = ['ffmpeg']
    out = run_command(cmd, timeout=timeout, verbose=verbose)
    return out

with Pool(jobs) as pool:

    def _callback(test_result) -> None:
        print(
            test_result,
            flush=True,
        )
        if failfast:
            pool.terminate()

    start = perf_counter()
    for test in tests:
        pool.apply_async(_run_worker, (test,), callback=_callback)
    pool.close()
    pool.join()

Fixes #147

[1] https://lists.gnu.org/archive/html/help-bash/2024-02/msg00084.html

Fix issue with Bash Linux terminal does not echo the input characters
after running a full test suite.

Thanks to Kerin Millar for the help in the bash list [1]

The issue could be reproduced with
```
from multiprocessing import Pool
from unittest.result import TestResult
from time import perf_counter
import subprocess

jobs=3
failfast=False
timeout=30
verbose=True
tests = [1,2,3]

def run_command(command, verbose = False, check = True, timeout = None):
    """Runs a command"""
    sout = subprocess.DEVNULL if not verbose else None
    serr = subprocess.DEVNULL if not verbose else None
    if verbose:
        print(f'\nRunning command "{" ".join(command)}"')
    try:
        subprocess.run(command, stdout=sout, stderr=serr, check=check, timeout=timeout)
    except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as ex:
        raise ex

def _run_worker(test):
    print("running", test)
    cmd = ['ffmpeg']
    out = run_command(cmd, timeout=timeout, verbose=verbose)
    return out

with Pool(jobs) as pool:

    def _callback(test_result) -> None:
        print(
            test_result,
            flush=True,
        )
        if failfast:
            pool.terminate()

    start = perf_counter()
    for test in tests:
        pool.apply_async(_run_worker, (test,), callback=_callback)
    pool.close()
    pool.join()
```

Fixes #147

[1] https://lists.gnu.org/archive/html/help-bash/2024-02/msg00084.html
@dabrain34
Copy link
Contributor

LGTM !

@mdimopoulos mdimopoulos merged commit 113299e into master Feb 19, 2024
3 checks passed
@mdimopoulos mdimopoulos deleted the ffmpeg_nostdin branch February 19, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

terminal: input characters echoing is broken after running a test suite
3 participants