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:
20
common.py
20
common.py
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user