comparison rhodecode/lib/compat.py @ 2730:7949bc80b3b1 beta

more py25 compat fixes
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 22 Aug 2012 13:30:52 +0200
parents e9e7c40b4f1a
children 3c0ae44557c4
comparison
equal deleted inserted replaced
2729:e9e7c40b4f1a 2730:7949bc80b3b1
528 from copy import deepcopy 528 from copy import deepcopy
529 result = self.__class__() 529 result = self.__class__()
530 memo[id(self)] = result 530 memo[id(self)] = result
531 result.__init__(deepcopy(tuple(self), memo)) 531 result.__init__(deepcopy(tuple(self), memo))
532 return result 532 return result
533
534
535 #==============================================================================
536 # threading.Event
537 #==============================================================================
538
539 if __py_version__ >= (2, 6):
540 from threading import Event
541 else:
542 from threading import _Verbose, Condition, Lock
543
544 def Event(*args, **kwargs):
545 return _Event(*args, **kwargs)
546
547 class _Event(_Verbose):
548
549 # After Tim Peters' event class (without is_posted())
550
551 def __init__(self, verbose=None):
552 _Verbose.__init__(self, verbose)
553 self.__cond = Condition(Lock())
554 self.__flag = False
555
556 def isSet(self):
557 return self.__flag
558
559 is_set = isSet
560
561 def set(self):
562 self.__cond.acquire()
563 try:
564 self.__flag = True
565 self.__cond.notify_all()
566 finally:
567 self.__cond.release()
568
569 def clear(self):
570 self.__cond.acquire()
571 try:
572 self.__flag = False
573 finally:
574 self.__cond.release()
575
576 def wait(self, timeout=None):
577 self.__cond.acquire()
578 try:
579 if not self.__flag:
580 self.__cond.wait(timeout)
581 finally:
582 self.__cond.release()
583
584
585