Mercurial > kallithea
changeset 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 | 09d8fec02954 |
files | rhodecode/lib/compat.py rhodecode/lib/subprocessio.py |
diffstat | 2 files changed, 58 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/lib/compat.py Wed Aug 22 12:09:49 2012 +0200 +++ b/rhodecode/lib/compat.py Wed Aug 22 13:30:52 2012 +0200 @@ -530,3 +530,56 @@ memo[id(self)] = result result.__init__(deepcopy(tuple(self), memo)) return result + + +#============================================================================== +# threading.Event +#============================================================================== + +if __py_version__ >= (2, 6): + from threading import Event +else: + from threading import _Verbose, Condition, Lock + + def Event(*args, **kwargs): + return _Event(*args, **kwargs) + + class _Event(_Verbose): + + # After Tim Peters' event class (without is_posted()) + + def __init__(self, verbose=None): + _Verbose.__init__(self, verbose) + self.__cond = Condition(Lock()) + self.__flag = False + + def isSet(self): + return self.__flag + + is_set = isSet + + def set(self): + self.__cond.acquire() + try: + self.__flag = True + self.__cond.notify_all() + finally: + self.__cond.release() + + def clear(self): + self.__cond.acquire() + try: + self.__flag = False + finally: + self.__cond.release() + + def wait(self, timeout=None): + self.__cond.acquire() + try: + if not self.__flag: + self.__cond.wait(timeout) + finally: + self.__cond.release() + + +
--- a/rhodecode/lib/subprocessio.py Wed Aug 22 12:09:49 2012 +0200 +++ b/rhodecode/lib/subprocessio.py Wed Aug 22 13:30:52 2012 +0200 @@ -25,7 +25,7 @@ import os import subprocess import threading -from rhodecode.lib.compat import deque +from rhodecode.lib.compat import deque, Event class StreamFeeder(threading.Thread): @@ -89,16 +89,16 @@ self.chunk_count_max = int(buffer_size / chunk_size) + 1 self.chunk_size = chunk_size - self.data_added = threading.Event() + self.data_added = Event() self.data_added.clear() - self.keep_reading = threading.Event() + self.keep_reading = Event() self.keep_reading.set() - self.EOF = threading.Event() + self.EOF = Event() self.EOF.clear() - self.go = threading.Event() + self.go = Event() self.go.set() def stop(self):