Android: Fix broken Python multiprocessing module (a Kodi 19.2 bug)

This commit is contained in:
croneter 2021-09-30 14:33:43 +02:00
parent 352b36d32b
commit 3d535fe2bf

View file

@ -23,6 +23,11 @@ import re
import gc import gc
try: try:
from multiprocessing.pool import ThreadPool from multiprocessing.pool import ThreadPool
# Annyoing Kodi bug on Android, introduced with
# https://github.com/xbmc/xbmc/pull/20034
# See https://github.com/croneter/PlexKodiConnect/issues/1641
with ThreadPool():
pass
SUPPORTS_POOL = True SUPPORTS_POOL = True
except Exception: except Exception:
SUPPORTS_POOL = False SUPPORTS_POOL = False
@ -867,13 +872,12 @@ def process_method_on_list(method_to_run, items):
all_items = [] all_items = []
if SUPPORTS_POOL: if SUPPORTS_POOL:
pool = ThreadPool() pool = ThreadPool()
with ThreadPool() as pool:
try: try:
all_items = pool.map(method_to_run, items) all_items = pool.map(method_to_run, items)
except Exception: except Exception:
# catch exception to prevent threadpool running forever # catch exception to prevent threadpool running forever
ERROR(notify=True) ERROR(notify=True)
pool.close()
pool.join()
else: else:
all_items = [method_to_run(item) for item in items] all_items = [method_to_run(item) for item in items]
all_items = [_f for _f in all_items if _f] all_items = [_f for _f in all_items if _f]