Locking mechanism

This commit is contained in:
Ruud
2014-09-16 22:44:33 +02:00
parent 002ce4d4e1
commit f7eeaf3eda
3 changed files with 26 additions and 3 deletions
+19
View File
@@ -1,3 +1,4 @@
import threading
from urllib import quote
from urlparse import urlparse
import glob
@@ -35,6 +36,8 @@ class Plugin(object):
_needs_shutdown = False
_running = None
_locks = {}
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20130519 Firefox/24.0'
http_last_use = {}
http_time_between_calls = 0
@@ -393,3 +396,19 @@ class Plugin(object):
def isEnabled(self):
return self.conf(self.enabled_option) or self.conf(self.enabled_option) is None
def acquireLock(self, key):
lock = self._locks.get(key)
if not lock:
self._locks[key] = threading.RLock()
log.debug('Acquiring lock: %s', key)
self._locks.get(key).acquire()
def releaseLock(self, key):
lock = self._locks.get(key)
if lock:
log.debug('Releasing lock: %s', key)
self._locks.get(key).release()