refactored pluginsystem
This commit is contained in:
20
config.py
20
config.py
@@ -14,6 +14,7 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
import threading
|
||||
|
||||
from fasteners import interprocess_locked
|
||||
from configobj import ConfigObj
|
||||
@@ -33,6 +34,8 @@ runtime_config_store = ConfigObj(
|
||||
encoding='utf-8'
|
||||
)
|
||||
|
||||
config_lock = threading.Lock()
|
||||
|
||||
result = __config_store.validate(Validator())
|
||||
# copy is essential to store values with a default.. see configobj.py:2053
|
||||
assert runtime_config_store.validate(Validator(), copy=True)
|
||||
@@ -84,6 +87,23 @@ def runtimeconf_persist():
|
||||
runtime_config_store.write()
|
||||
|
||||
|
||||
def config_locked(f):
|
||||
"""A decorator that makes access to the config thread-safe"""
|
||||
|
||||
def decorate(*args, **kwargs):
|
||||
|
||||
config_lock.acquire()
|
||||
|
||||
try:
|
||||
return f(*args, **kwargs)
|
||||
except:
|
||||
raise
|
||||
finally:
|
||||
config_lock.release()
|
||||
|
||||
return decorate
|
||||
|
||||
|
||||
def runtimeconf_deepget(key, default=None):
|
||||
"""
|
||||
access a nested key with get("plugins.moin.enabled")
|
||||
|
||||
Reference in New Issue
Block a user