Merge pull request #1644 from croneter/py3-fix-multiprocessing

Android: Fix broken Python multiprocessing module (a Kodi 19.2 bug)
This commit is contained in:
croneter 2021-09-30 14:57:33 +02:00 committed by GitHub
commit d4f9dd427f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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()
try: with ThreadPool() as pool:
all_items = pool.map(method_to_run, items) try:
except Exception: all_items = pool.map(method_to_run, items)
# catch exception to prevent threadpool running forever except Exception:
ERROR(notify=True) # catch exception to prevent threadpool running forever
pool.close() ERROR(notify=True)
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]