Skip to content

Commit 86f1802

Browse files
committed
Address possible race condition resulting in KeyError exception when calling pop() on an empty set
- Also move batch set mutation operations out of worker method and into wrapping _threaded_fetch method
1 parent a505862 commit 86f1802

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

resources/lib/youtube_plugin/youtube/client/data_client.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,8 +2392,7 @@ def _get_cached_feed(output,
23922392
else:
23932393
channel_prefix = False
23942394

2395-
batch = inputs.copy()
2396-
for item_id in batch:
2395+
for item_id in inputs:
23972396
if channel_prefix:
23982397
channel_id = item_id
23992398
item_id = item_id.replace('UC', channel_prefix, 1)
@@ -2419,7 +2418,6 @@ def _get_cached_feed(output,
24192418
else:
24202419
to_refresh.add(channel_id)
24212420

2422-
inputs -= batch
24232421
return True, False
24242422

24252423
def _get_feed(output,
@@ -2642,11 +2640,18 @@ def _threaded_fetch(kwargs,
26422640
_kwargs = {}
26432641
elif kwargs:
26442642
if do_batch:
2645-
_kwargs = {'inputs': kwargs}
2646-
elif unpack:
2647-
_kwargs = {'input': kwargs.pop()}
2643+
batch = kwargs.copy()
2644+
kwargs -= batch
2645+
_kwargs = {'inputs': batch}
26482646
else:
2649-
_kwargs = kwargs.pop()
2647+
try:
2648+
_kwargs = kwargs.pop()
2649+
except KeyError:
2650+
if check_inputs:
2651+
check_inputs.clear()
2652+
break
2653+
if unpack:
2654+
_kwargs = {'input': _kwargs}
26502655
elif check_inputs:
26512656
if check_inputs.wait(0.1) and kwargs:
26522657
continue

0 commit comments

Comments
 (0)