Fix video_dl hanging silently (blocking event loop)#181
Merged
Conversation
Synchronous yt_dlp.YoutubeDL calls (probe + download) and catboxpy's client.upload() were blocking the asyncio event loop. The typing indicator fired but nothing else could run — no download, no reply, no log output. Wraps both in asyncio.to_thread() via inner _run_download / _do_upload helpers so the event loop stays free. Also guards on_message catbox path against message.guild being None (DM context), which would have raised AttributeError after a successful download in a DM. Closes #180
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
video_dlwas showing a typing indicator but never responding. The root cause was synchronous blocking I/O running directly on the asyncio event loop.Root cause
yt_dlp.YoutubeDL.extract_info()(both the size-probe pass and the actual download) andcatboxpy'sclient.upload()are synchronous calls. Calling them inside anasyncfunction without offloading to a thread freezes the entire event loop — the typing indicator heartbeat can't fire, no reply is ever sent, and no error appears in logs.Changes
asyncio.to_thread(_run_download)so the event loop stays freeclient.upload()inasyncio.to_thread(_do_upload)for the same reasonimport asyncio(was missing)on_message's catbox/emoji paths againstmessage.guild is None(DM context where the bot owner triggers a download — previously would raiseAttributeError)Testing
python -m py_compile video_dl/video_dl.pyflake8 video_dl/video_dl.py --select=E9,F63,F7,F82Risk
Low. Change is isolated to threading the I/O work off the event loop — no logic changes to download/upload behaviour. DM guard is defensive and was always a latent crash.
Closes #180