From 491440543571b07c849c0ef9c4ebf5c27f263bc0 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 7 Jan 2015 11:18:07 +0100 Subject: Implemented non-blocking operations using poll() Next up is using threads --- git/util.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'git/util.py') diff --git a/git/util.py b/git/util.py index 4de736d3..34b09d32 100644 --- a/git/util.py +++ b/git/util.py @@ -249,6 +249,14 @@ class RemoteProgress(object): # END for each sub line return failed_lines + def new_message_handler(self): + """:return: a progress handler suitable for handle_process_output(), passing lines on to this Progress + handler in a suitable format""" + def handler(line): + return self._parse_progress_line(line.rstrip()) + # end + return handler + def line_dropped(self, line): """Called whenever a line could not be understood and was therefore dropped.""" pass -- cgit v1.2.1 From 763ef75d12f0ad6e4b79a7df304c7b5f1b5a11f2 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 7 Jan 2015 12:32:45 +0100 Subject: Using a wait-group seems to properly sync the threads for buffer depletion --- git/util.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'git/util.py') diff --git a/git/util.py b/git/util.py index 34b09d32..e211ca41 100644 --- a/git/util.py +++ b/git/util.py @@ -12,6 +12,7 @@ import stat import shutil import platform import getpass +import threading # NOTE: Some of the unused imports might be used/imported by others. # Handle once test-cases are back up and running. @@ -32,7 +33,7 @@ from gitdb.util import ( # NOQA __all__ = ("stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux", "join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList", "BlockingLockFile", "LockFile", 'Actor', 'get_user_id', 'assure_directory_exists', - 'RemoteProgress', 'rmtree') + 'RemoteProgress', 'rmtree', 'WaitGroup') #{ Utility Methods @@ -699,3 +700,32 @@ class Iterable(object): raise NotImplementedError("To be implemented by Subclass") #} END classes + + +class WaitGroup(object): + """WaitGroup is like Go sync.WaitGroup. + + Without all the useful corner cases. + By Peter Teichman, taken from https://gist.github.com/pteichman/84b92ae7cef0ab98f5a8 + """ + def __init__(self): + self.count = 0 + self.cv = threading.Condition() + + def add(self, n): + self.cv.acquire() + self.count += n + self.cv.release() + + def done(self): + self.cv.acquire() + self.count -= 1 + if self.count == 0: + self.cv.notify_all() + self.cv.release() + + def wait(self): + self.cv.acquire() + while self.count > 0: + self.cv.wait() + self.cv.release() -- cgit v1.2.1 From 87a6ffa13ae2951a168cde5908c7a94b16562b96 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 7 Jan 2015 12:37:49 +0100 Subject: Fix flake8 --- git/util.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'git/util.py') diff --git a/git/util.py b/git/util.py index e211ca41..4d1ea8d6 100644 --- a/git/util.py +++ b/git/util.py @@ -251,7 +251,7 @@ class RemoteProgress(object): return failed_lines def new_message_handler(self): - """:return: a progress handler suitable for handle_process_output(), passing lines on to this Progress + """:return: a progress handler suitable for handle_process_output(), passing lines on to this Progress handler in a suitable format""" def handler(line): return self._parse_progress_line(line.rstrip()) @@ -704,26 +704,26 @@ class Iterable(object): class WaitGroup(object): """WaitGroup is like Go sync.WaitGroup. - + Without all the useful corner cases. By Peter Teichman, taken from https://gist.github.com/pteichman/84b92ae7cef0ab98f5a8 """ def __init__(self): self.count = 0 self.cv = threading.Condition() - + def add(self, n): self.cv.acquire() self.count += n self.cv.release() - + def done(self): self.cv.acquire() self.count -= 1 if self.count == 0: self.cv.notify_all() self.cv.release() - + def wait(self): self.cv.acquire() while self.count > 0: -- cgit v1.2.1