Ensure that only one thread accesses settings.xml
Avoids corruption of settings.xml
This commit is contained in:
parent
7d2f785a8d
commit
030c381f65
1 changed files with 13 additions and 7 deletions
|
@ -8,6 +8,7 @@ from logging import getLogger
|
|||
from sqlite3 import connect, OperationalError
|
||||
from datetime import datetime
|
||||
from unicodedata import normalize
|
||||
from threading import Lock
|
||||
try:
|
||||
import xml.etree.cElementTree as etree
|
||||
import defusedxml.cElementTree as defused_etree # etree parse unsafe
|
||||
|
@ -36,6 +37,10 @@ LOG = getLogger('PLEX.utils')
|
|||
WINDOW = xbmcgui.Window(10000)
|
||||
ADDON = xbmcaddon.Addon(id='plugin.video.plexkodiconnect')
|
||||
|
||||
# If several threads access the settings.xml file concurrently, it gets
|
||||
# corrupted
|
||||
SETTINGS_LOCK = Lock()
|
||||
|
||||
# Grab Plex id from '...plex_id=XXXX....'
|
||||
REGEX_PLEX_ID = re.compile(r'''plex_id=(\d+)''')
|
||||
# Return the numbers at the end of an url like '.../.../XXXX'
|
||||
|
@ -122,6 +127,7 @@ def settings(setting, value=None):
|
|||
setting and value can either be unicode or string
|
||||
"""
|
||||
# We need to instantiate every single time to read changed variables!
|
||||
with SETTINGS_LOCK:
|
||||
addon = xbmcaddon.Addon(id='plugin.video.plexkodiconnect')
|
||||
if value is not None:
|
||||
# Takes string or unicode by default!
|
||||
|
|
Loading…
Reference in a new issue