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

Keyboard interrupt not working on Windows #52

Open
pdc1 opened this issue Apr 12, 2024 · 4 comments
Open

Keyboard interrupt not working on Windows #52

pdc1 opened this issue Apr 12, 2024 · 4 comments

Comments

@pdc1
Copy link

pdc1 commented Apr 12, 2024

Hello,

I have found that keyboard interrupt does not work on Windows (I haven't tested it on other platforms).

What I found is that concurrent.futures.wait() does not return on the keyboard interrupt, making it necessary to introduce a timeout so the system can process the exception.

In ffmpeg.py execute() I tried changing:

            done, pending = concurrent.futures.wait(futures, return_when=concurrent.futures.FIRST_EXCEPTION)
            self._executed = False

to:

            pending = futures
            try:
                while pending:
                    done, pending = concurrent.futures.wait(
                        futures,
                        timeout=1,
                        return_when=concurrent.futures.FIRST_EXCEPTION,
                    )
            except KeyboardInterrupt as e:
                self.terminate()
                executor.shutdown(wait=True, cancel_futures=True)
                raise e
            self._executed = False

With that change, keyboard interrupt works as expected.

@jonghwanhyeon
Copy link
Owner

jonghwanhyeon commented Apr 15, 2024

KeyboardInterrupt.mov

It seems working on my environment:

  • Windows 11
  • Python 3.12

(The response time seems to be a bit slow. A Keyboard Interrupt occurs 1-2 seconds after pressing Control C.)

@pdc1
Copy link
Author

pdc1 commented Apr 15, 2024

Interesting, I wonder if there is something else going on in my environment -- I do have multiple thread pools running (multiple ffmpeg in parallel with progress). I have not seen keyboard interrupt work on Windows 10 or 11 with python 3.11.

@wheezy1749
Copy link

wheezy1749 commented Jul 14, 2024

Wondering if this is related to this issue as my ffmpeg is infinitely hanging unless I press ENTER on my keyboard. Then it continues.

Progress(frame=0, fps=0.0, size=2400256, time=datetime.timedelta(seconds=11), bitrate=1745.1, speed=1860.0)

If instead of ENTER I hit CTRL+C the code is hanging at the same location.

done, pending = concurrent.futures.wait(futures, return_when=concurrent.futures.FIRST_EXCEPTION)

And oddly enough if I run my same code through PyTest it never hangs.

Edit: Seems to be related to issuing the exact same command with the same files. My Pytest suite was handling multiple different files but running the code from my main function was trying to handle the same file. No ffmpeg process was still running still. Just issuing a different command to call ffmpeg again seems to fix the issue with whatever process (that I can't see listed anywhere) is holding the files and hanging ffmpeg. No idea why hitting ENTER fixed it either though. I'd guess its something with windows and how this library is handling the pass off to ffmpeg.

Edit2: Having pyautogui.press('enter') even stops the hang if I connect to ffmpeg.on("progress"). Very odd behavior.

@pdc1
Copy link
Author

pdc1 commented Jul 15, 2024 via email

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

No branches or pull requests

3 participants