Merge 0e26e2dd29df8f6ae93ef31d4ae7db8bddd883aa into df129c7ba30aaa9ffffb81a48f53aa7253b0b4e6

This commit is contained in:
David Singh 2024-03-29 17:18:15 +01:00 committed by GitHub
commit 6852a253ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,7 +5,7 @@ import argparse
import contextlib import contextlib
import ffmpeg import ffmpeg
import gevent import gevent
import gevent.monkey; gevent.monkey.patch_all(thread=False) import gevent.monkey
import os import os
import shutil import shutil
import socket import socket
@ -62,6 +62,16 @@ def _do_watch_progress(filename, sock, handler):
connection.close() 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 @contextlib.contextmanager
def _watch_progress(handler): def _watch_progress(handler):
"""Context manager for creating a unix-domain socket and listen for """Context manager for creating a unix-domain socket and listen for
@ -78,7 +88,7 @@ def _watch_progress(handler):
Yields: Yields:
socket_filename: the name of the socket file. 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') socket_filename = os.path.join(tmpdir, 'sock')
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
with contextlib.closing(sock): with contextlib.closing(sock):
@ -108,7 +118,7 @@ def show_progress(total_duration):
yield socket_filename yield socket_filename
if __name__ == '__main__': def main():
args = parser.parse_args() args = parser.parse_args()
total_duration = float(ffmpeg.probe(args.in_filename)['format']['duration']) total_duration = float(ffmpeg.probe(args.in_filename)['format']['duration'])
@ -128,3 +138,6 @@ if __name__ == '__main__':
print(e.stderr, file=sys.stderr) print(e.stderr, file=sys.stderr)
sys.exit(1) sys.exit(1)
if __name__ == '__main__':
main()