return time the process have to sleep, after consumed specified amount
(self, amount)
| 36 | self.lock.release() |
| 37 | |
| 38 | def consumed(self, amount): |
| 39 | """ return time the process have to sleep, after consumed specified amount """ |
| 40 | if self.rate < 10240: return 0 #min. 10kb, may become unresponsive otherwise |
| 41 | self.lock.acquire() |
| 42 | |
| 43 | self.calc_tokens() |
| 44 | self.tokens -= amount |
| 45 | |
| 46 | if self.tokens < 0: |
| 47 | time = -self.tokens/float(self.rate) |
| 48 | else: |
| 49 | time = 0 |
| 50 | |
| 51 | |
| 52 | self.lock.release() |
| 53 | return time |
| 54 | |
| 55 | def calc_tokens(self): |
| 56 | if self.tokens < self.rate: |
no test coverage detected