Skip to content

Fixed potential issues in examples/show_progress.py #829

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions examples/show_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import contextlib
import ffmpeg
import gevent
import gevent.monkey; gevent.monkey.patch_all(thread=False)
import gevent.monkey
import os
import shutil
import socket
Expand Down Expand Up @@ -62,6 +62,16 @@ def _do_watch_progress(filename, sock, handler):
connection.close()


class PatchSelectors():
def __enter__(self):
gevent.monkey.patch_selectors(aggressive=False)

def __exit__(self, *args, **kwargs):
import importlib
import selectors
importlib.reload(selectors)


@contextlib.contextmanager
def _watch_progress(handler):
"""Context manager for creating a unix-domain socket and listen for
Expand All @@ -78,7 +88,7 @@ def _watch_progress(handler):
Yields:
socket_filename: the name of the socket file.
"""
with _tmpdir_scope() as tmpdir:
with _tmpdir_scope() as tmpdir, PatchSelectors():
socket_filename = os.path.join(tmpdir, 'sock')
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
with contextlib.closing(sock):
Expand Down Expand Up @@ -108,7 +118,7 @@ def handler(key, value):
yield socket_filename


if __name__ == '__main__':
def main():
args = parser.parse_args()
total_duration = float(ffmpeg.probe(args.in_filename)['format']['duration'])

Expand All @@ -128,3 +138,6 @@ def handler(key, value):
print(e.stderr, file=sys.stderr)
sys.exit(1)

if __name__ == '__main__':
main()