From 433a314b254ef3fe0cf73db6f01057b17b91e0e2 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 7 Mar 2014 19:41:48 +0100 Subject: add support for signals in concurrently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/join.py | 16 +++++++++------- src/test.py | 6 ++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/join.py b/src/join.py index 76b7445..d057f90 100644 --- a/src/join.py +++ b/src/join.py @@ -217,13 +217,15 @@ def concurrently(*fs): ''' Run a set of functions concurrently and wait for all of them to return - @param fs:*()→void The functions to run - ''' - ts = [threading.Thread(target = f) for f in fs] - for t in ts: - t.start() - for t in ts: - t.join() + @param fs:*()→(void|join()→...) The functions to run + @return :list<...> The return of each functions, assuming it a signal + ''' + def t(f): + thread = threading.Thread(target = f) + thread.start() + return thread + ts = [f() if isinstance(f, signal) or isinstance(f, puresignal) else t(f) for f in fs] + return [t.join() for t in ts] diff --git a/src/test.py b/src/test.py index 6b4c8af..2538680 100755 --- a/src/test.py +++ b/src/test.py @@ -124,6 +124,12 @@ print(' Last (delayed c:a 1 s)') print() +print('Testing connurrently with @signal and @puresignal') +concurrently(signal(lambda : c(0)), signal(lambda : c(1)), puresignal(lambda : c(2)), puresignal(lambda : c(3))) +print(' Last (delayed c:a 1 s)') +print() + + @signal def fsig1(value): pass -- cgit v1.2.3-70-g09d2