python Programming Glossary: self.lock
How do I get a thread safe print in Python 2.6? http://stackoverflow.com/questions/3029816/how-do-i-get-a-thread-safe-print-in-python-2-6 class ThreadSafeFile object def __init__ self f self.f f self.lock threading.RLock self.nesting 0 def _getlock self self.lock.acquire.. self.lock threading.RLock self.nesting 0 def _getlock self self.lock.acquire self.nesting 1 def _droplock self nesting self.nesting.. nesting self.nesting self.nesting 0 for i in range nesting self.lock.release def __getattr__ self name if name 'softspace' return..
python - how to get the numebr of active threads started by specific class? http://stackoverflow.com/questions/4046986/python-how-to-get-the-numebr-of-active-threads-started-by-specific-class __init__ self super ActivePool self .__init__ self.active self.lock threading.Lock def makeActive self name with self.lock self.active.append.. self.lock threading.Lock def makeActive self name with self.lock self.active.append name def makeInactive self name with self.lock.. self.active.append name def makeInactive self name with self.lock self.active.remove name def numActive self with self.lock return..
Throttling with urllib2 http://stackoverflow.com/questions/456649/throttling-with-urllib2 self.fill_rate float fill_rate self.timestamp time.time self.lock threading.RLock def consume self tokens Consume tokens from.. the expected time until enough tokens become available. self.lock.acquire tokens max tokens self.tokens expected_time tokens self.tokens.. self.fill_rate if expected_time 0 self._tokens tokens self.lock.release return max 0 expected_time @property def tokens self..
|