diff options
| author | Astounds <kirito@disroot.org> | 2026-03-28 16:06:47 -0500 |
|---|---|---|
| committer | Astounds <kirito@disroot.org> | 2026-03-28 16:06:47 -0500 |
| commit | fa7273b328b8cea8b051917f5255a1a712a9e1b9 (patch) | |
| tree | c52212a4675792556c7e595dc4c8a3b3c8e187e4 /youtube/util.py | |
| parent | a0d10e6a007e6191f1fa34174fd08f4f2c3e580b (diff) | |
| download | yt-local-fa7273b328b8cea8b051917f5255a1a712a9e1b9.tar.lz yt-local-fa7273b328b8cea8b051917f5255a1a712a9e1b9.tar.xz yt-local-fa7273b328b8cea8b051917f5255a1a712a9e1b9.zip | |
fix: race condition in os.makedirs causing worker crashes
Replace check-then-create pattern with exist_ok=True to prevent
FileExistsError when multiple workers initialize simultaneously.
Affects:
- subscriptions.py: open_database()
- watch.py: save_decrypt_cache()
- local_playlist.py: add_to_playlist()
- util.py: fetch_url(), get_visitor_data()
- settings.py: initialization
Fixes Gunicorn worker startup failures in multi-worker deployments.
Diffstat (limited to 'youtube/util.py')
| -rw-r--r-- | youtube/util.py | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/youtube/util.py b/youtube/util.py index ebb5307..3f48c84 100644 --- a/youtube/util.py +++ b/youtube/util.py @@ -343,8 +343,7 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None, and debug_name is not None and content): save_dir = os.path.join(settings.data_dir, 'debug') - if not os.path.exists(save_dir): - os.makedirs(save_dir) + os.makedirs(save_dir, exist_ok=True) with open(os.path.join(save_dir, debug_name), 'wb') as f: f.write(content) @@ -902,8 +901,7 @@ INNERTUBE_CLIENTS = { def get_visitor_data(): visitor_data = None visitor_data_cache = os.path.join(settings.data_dir, 'visitorData.txt') - if not os.path.exists(settings.data_dir): - os.makedirs(settings.data_dir) + os.makedirs(settings.data_dir, exist_ok=True) if os.path.isfile(visitor_data_cache): with open(visitor_data_cache, 'r') as file: print('Getting visitor_data from cache') |
