1
0
mirror of http://aero2k.de/t/repos/urlbot-native.git synced 2017-09-06 15:25:38 +02:00

patch by braph: use decorator for config lock, drop IPC lock

This commit is contained in:
Thorsten
2016-04-03 21:20:14 +02:00
parent 89db85ad59
commit fca53d869f
5 changed files with 27 additions and 33 deletions

View File

@@ -7,6 +7,7 @@ import time
import requests
from collections import namedtuple
from urllib.error import URLError
import threading
RATE_NO_LIMIT = 0x00
RATE_GLOBAL = 0x01
@@ -43,6 +44,8 @@ buckets = {
rate_limit_classes = buckets.keys()
plugin_lock = threading.Lock()
def rate_limit(rate_class=RATE_GLOBAL):
"""
@@ -182,6 +185,23 @@ def giphy(subject, api_key):
return giphy_url
def config_locked(f):
"""A decorator that makes access to the config thread-safe"""
def decorate(*args, **kwargs):
plugin_lock.acquire()
try:
return f(*args, **kwargs)
except:
raise
finally:
plugin_lock.release()
return decorate
def pluginfunction(name, desc, plugin_type, ratelimit_class=RATE_GLOBAL, enabled=True):
"""A decorator to make a plugin out of a function
:param enabled: