anitopy
anitopy copied to clipboard
Stop using singletons
Currently the Elements
and Tokens
classes are singletons. The problem is that we have to be very careful to clean everything between each parse or else state from a previous parse may remain in future parses.
It would be much better if a new instance was created at every parse to ensure total isolation.
The singletons can cause a race condition bug in multi thread where 2 difference thread trying to parse at the same time. From my experience, I got a list of anime_title
from 2 difference anime. For now, this bug can be fix using threading.RLock()
before parse it.
Here my traceback.
File "/root/Anime-downloader/src/torrent/upload.py", line 24, in upload
anime = recognition.track(file_name)
file_name = '[Judas] Code Geass Movie 04 - Lelouch of the Re;surrection.mkv'
file_path = '[Judas] Code Geass - Hangyaku no Lelouch (Lelouch of the Rebellion) (Seasons 1-2 + Movies + OVAs) [BD 1080p][HEVC x265 10bit][Dual-Audio][Eng-Subs]/[Judas] Code Geass Movies/[Judas] Code Geass Movie 04 - Lelouch of the Re;surrection.mkv'
folder_path = '[Judas] Code Geass - Hangyaku no Lelouch (Lelouch of the Rebellion) (Seasons 1-2 + Movies + OVAs) [BD 1080p][HEVC x265 10bit][Dual-Audio][Eng-Subs]/[Judas] Code Geass Movies'
local_save_path = '//Downloads'
num_retries = 10
save_path = '//Downloads'
torrent_path = ['[Judas] Code Geass - Hangyaku no Lelouch (Lelouch of the Rebellion) (Seasons 1-2 + Movies + OVAs) [BD 1080p][HEVC x265 10bit][Dual-Audio][Eng-Subs]', '[Judas] Code Geass Movies']
track = True
File "/root/Anime-downloader/deps/recognition/recognition/recognition.py", line 348, in track
anime = parsing(anime_filename, is_folder)
anime_filename = '[Judas] Code Geass Movie 04 - Lelouch of the Re;surrection.mkv'
anime_filepath = '[Judas] Code Geass Movie 04 - Lelouch of the Re;surrection.mkv'
folder_path = ''
is_folder = False
File "/root/Anime-downloader/deps/recognition/recognition/recognition.py", line 471, in parsing
anime_name = re.sub(r"[(\[{].*?[)\]}]|[-:]", ' ', anime['anime_title'])
anime = {
'file_name': '[ASW] Bucchigire! - 04 [1080p HEVC][F321EB41].mkv',
'file_extension': 'mkv',
'video_resolution': '1080p',
'video_term': 'HEVC',
'file_checksum': 'F321EB41',
'episode_number': '04',
'anime_title': ['Bucchigire!', 'Code Geass Movie 04 - Lelouch of the Re;surrection'],
'release_group': 'ASW',
'anime_type': 'Movie'
}
filename = '[Judas] Code Geass Movie 04 - Lelouch of the Re;surrection.mkv'
is_folder = False
That's a good point. This is worse than I previously thought.
I will try to fix this as soon as possible.