Commits

Valentino Volonghi aka dialtone  committed 5b9846a

bump to 0.0.6 and fix the annoying lock up with high frequency

  • Participants
  • Parent commits c8e42c2

Comments (0)

Files changed (2)

File turtl/__init__.py

-__version__ = '0.0.5'
+__version__ = '0.0.6'

File turtl/engine.py

 from twisted.internet import defer, task
 
-class IntervalTooShortError(Exception):
-    pass
-
 class _ConcurrencyPrimitive(object):
     _execute = defer.maybeDeferred
 
         """
         _ConcurrencyPrimitive.__init__(self)
 
-        if interval < .1:
-            raise IntervalTooShortError("Can't set interval less than .1. Raise the number of calls")
-
         self._sem = defer.DeferredSemaphore(concurrency)
         self._execute = self._sem.run
 
 
         self._resetLoop = task.LoopingCall(self._reset)
         self._resetLoop.start(interval, now=False)
+        self._lastReset = None
 
     def _reset(self):
         # We don't want to release while calls are in timeout mode
         # so we schedule the release to run right after a request
         # has completed.
         self.points = self.calls
-        self._sem.run(self.release)
+        # If we don't check for this we will overflow the queue on long running calls.
+        if self._lastReset and self._lastReset.called:
+            self._lastReset = self._sem.run(self.release)
 
     def acquire(self, priority=False):
         """Attempt to acquire the token.