I randomly get Process finished with exit code -1073741819 (0xC0000005) while my thread function is running. My program made on pyqt5 and have function that downloads videos from YouTube with yt-dlp and when I try to download some videos, I get this error, sometimes the function itself is executed completely without errors, but at the end of its execution, an error still appears.
My func
def DOWNLOAD(self):
if not self.LINEEDIT_LINK.text() == '' and _FILE_SIZE > 0:
self.PUSHBUTTON_DOWNLOAD.setEnabled(False)
self.PUSHBUTTON_DOWNLOAD.setStyleSheet(set_download_button_font_size(14))
downloadThread = Thread(target=self.download_thread)
downloadThread.daemon = True
downloadThread.start()
def my_hook(self, d):
if d['status'] == 'downloading':
self.__cleen_percent(dl=d)
elif d['status'] == 'finished':
self.PROGRESSBAR.setValue(0)
self.PUSHBUTTON_DOWNLOAD.setText("Download")
self.PUSHBUTTON_DOWNLOAD.setCheckable(True)
def __cleen_percent(self, dl):
network_speed = dl['_speed_str']
percent = dl['_percent_str']
all_mb = round(dl['total_bytes_estimate'] / 1024 / 1024, 2)
downloaded_mb = round(dl['downloaded_bytes'] / 1024 / 1024, 2)
eta = dl['eta']
for i, char in enumerate(percent):
if char == '%':
value = percent[i - 5:i + 1].replace('%', '')
value = (float(value.replace(' ', '')))
self.PROGRESSBAR.setValue(int(value))
self.PUSHBUTTON_DOWNLOAD.setText(
f'{network_speed} | {downloaded_mb} MB / {all_mb} MB | eta: {eta} secs')
break
# YOUTUBE THREADS
def download_thread(self):
try:
ydl_opts_download = {
'outtmpl': FOLDER_TO_SAVE + '/%(title)s.%(ext)s',
'format': f"bv*[height<={_RESOLUTION}][ext={_VIDEO_FORMAT}]+ba[ext=m4a]/b[height<={_RESOLUTION}][ext={_VIDEO_FORMAT}] / bv*+ba/b",
'progress_hooks': [self.my_hook],
}
ydl_opts_download_auto = {
'outtmpl': FOLDER_TO_SAVE + '/%(title)s.%(ext)s',
'format': f"bv*[height<={_RESOLUTION}]+ba[ext=m4a]/b[height<={_RESOLUTION}] / bv*+ba/b",
'progress_hooks': [self.my_hook],
}
ydl_opts_download_maxres = {
'outtmpl': FOLDER_TO_SAVE + '/%(title)s.%(ext)s',
'format': f"bv*[ext={_VIDEO_FORMAT}]+ba[ext=m4a]/b[ext={_VIDEO_FORMAT}] / bv*+ba/b",
'progress_hooks': [self.my_hook],
}
ydl_opts_download_maxres_auto = {
'outtmpl': FOLDER_TO_SAVE + '/%(title)s.%(ext)s',
'format': f"bv*+ba[ext=m4a]/b / bv*+ba/b",
'progress_hooks': [self.my_hook],
}
if FILE_TYPE == 0:
if MAX_RESOLUTION is True:
with YoutubeDL(ydl_opts_download_maxres_auto) as ydl:
ydl.download([_URL])
else:
with YoutubeDL(ydl_opts_download_auto) as ydl:
ydl.download([_URL])
else:
if MAX_RESOLUTION is True:
with YoutubeDL(ydl_opts_download_maxres) as ydl:
ydl.download([_URL])
else:
with YoutubeDL(ydl_opts_download) as ydl:
ydl.download([_URL])
if OPEN_FOLDER is True:
startfile(FOLDER_TO_SAVE)
if NOTIFICATIONS is True:
match LANGUAGE:
case 0:
toast.show_toast(
"Youtube Downloader",
"Video downloaded",
duration=5,
threaded=True,
icon_path=load_file("icons/youtube-downloader-icon.ico"),
)
case 1:
toast.show_toast(
"Youtube Downloader",
"Видео скачано",
duration=5,
threaded=True,
icon_path=load_file("icons/youtube-downloader-icon.ico"),
)
if CLOSE_APP is True:
QCoreApplication.quit()
self.PUSHBUTTON_DOWNLOAD.setEnabled(True)
self.PUSHBUTTON_DOWNLOAD.setStyleSheet(set_download_button_font_size(16))
except Exception as e:
print(e)
self.PUSHBUTTON_DOWNLOAD.setEnabled(True)
self.PUSHBUTTON_DOWNLOAD.setStyleSheet(set_download_button_font_size(16))
Here is the terminal output while download_thread is running
[youtube] YBBbNbumaoM: Downloading webpage
[youtube] YBBbNbumaoM: Downloading android player API JSON
[youtube] YBBbNbumaoM: Downloading MPD manifest
[info] YBBbNbumaoM: Downloading 1 format(s): 248+140
[dashsegments] Total fragments: 111
[download] Destination: E:\code\PycharmProjects\pythonProject\YOUTUBE_DOWNLOADER_2\videos\Free Bird Isolated Guitar Track HQ.f248.webm
[download] 37.8% of ~ 11.91MiB at 933.49KiB/s ETA 00:08 (frag 42/111)Windows fatal exception: access violation
Thread 0x00002544 (most recent call first):
File "E:\code\PycharmProjects\pythonProject\YOUTUBE_DOWNLOADER_2\downloader.py", line 1184 in __cleen_percent
File "E:\code\PycharmProjects\pythonProject\YOUTUBE_DOWNLOADER_2\downloader.py", line 1166 in my_hook
File "E:\code\Python\Lib\site-packages\yt_dlp\downloader\common.py", line 459 in _hook_progress
File "E:\code\Python\Lib\site-packages\yt_dlp\downloader\fragment.py", line 284 in frag_progress_hook
File "E:\code\Python\Lib\site-packages\yt_dlp\downloader\common.py", line 459 in _hook_progress
File "E:\code\Python\Lib\site-packages\yt_dlp\downloader\http.py", line 314 in download
File "E:\code\Python\Lib\site-packages\yt_dlp\downloader\http.py", line 377 in real_download
File "E:\code\Python\Lib\site-packages\yt_dlp\downloader\common.py", line 444 in download
File "E:\code\Python\Lib\site-packages\yt_dlp\downloader\fragment.py", line 124 in _download_fragment
File "E:\code\Python\Lib\site-packages\yt_dlp\downloader\fragment.py", line 469 in download_fragment
File "E:\code\Python\Lib\site-packages\yt_dlp\downloader\fragment.py", line 521 in download_and_append_fragments
File "E:\code\Python\Lib\site-packages\yt_dlp\downloader\fragment.py", line 382 in download_and_append_fragments_multiple
File "E:\code\Python\Lib\site-packages\yt_dlp\downloader\dash.py", line 60 in real_download
File "E:\code\Python\Lib\site-packages\yt_dlp\downloader\common.py", line 444 in download
File "E:\code\Python\Lib\site-packages\yt_dlp\YoutubeDL.py", line 2970 in dl
File "E:\code\Python\Lib\site-packages\yt_dlp\YoutubeDL.py", line 3229 in process_info
File "E:\code\Python\Lib\site-packages\yt_dlp\YoutubeDL.py", line 2779 in process_video_result
File "E:\code\Python\Lib\site-packages\yt_dlp\YoutubeDL.py", line 1674 in process_ie_result
File "E:\code\Python\Lib\site-packages\yt_dlp\YoutubeDL.py", line 1615 in __extract_info
File "E:\code\Python\Lib\site-packages\yt_dlp\YoutubeDL.py", line 1518 in wrapper
File "E:\code\Python\Lib\site-packages\yt_dlp\YoutubeDL.py", line 1507 in extract_info
File "E:\code\Python\Lib\site-packages\yt_dlp\YoutubeDL.py", line 3344 in wrapper
File "E:\code\Python\Lib\site-packages\yt_dlp\YoutubeDL.py", line 3369 in download
File "E:\code\PycharmProjects\pythonProject\YOUTUBE_DOWNLOADER_2\downloader.py", line 1222 in download_thread
File "E:\code\Python\Lib\threading.py", line 975 in run
File "E:\code\Python\Lib\threading.py", line 1038 in _bootstrap_inner
File "E:\code\Python\Lib\threading.py", line 995 in _bootstrap
Current thread 0x00002cb0 (most recent call first):
File "E:\code\PycharmProjects\pythonProject\YOUTUBE_DOWNLOADER_2\downloader.py", line 1451 in <module>
[download] 39.6% of ~ 11.92MiB at 49.16KiB/s ETA 00:11 (frag 44/111)
Process finished with exit code -1073741819 (0xC0000005)
When I run the same function without a thread and try to download the same video, the function runs without errors and downloads the video, but in this case the program interface does not respond while the function is running