diff options
author | Jason Kölker <jason@koelker.net> | 2016-03-20 09:20:27 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-23 22:30:14 +0900 |
commit | 545645eef89b205c8b53def424d6163d9cf8e896 (patch) | |
tree | 550a27719ac35328d7ae99e9d2c8aee198fb2074 | |
parent | 69744305b96c4b9a4b30979b39be4ff3aa4b3622 (diff) |
hub: Preserve functions return value
Calling GreenThread.wait() should return the value of the greenthread or
reraise the exception. As it is being wrapped to mimic gevent's .join
behaviour introduce the `raise_error` kwarg to allow callers to specify
the behavior they expect while maintaining backwards compatability.
Signed-off-by: Jason Kölker <jason@koelker.net>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/hub.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/ryu/lib/hub.py b/ryu/lib/hub.py index 91866599..2ec8d691 100644 --- a/ryu/lib/hub.py +++ b/ryu/lib/hub.py @@ -45,14 +45,18 @@ if HUB_TYPE == 'eventlet': connect = eventlet.connect def spawn(*args, **kwargs): + raise_error = kwargs.pop('raise_error', False) + def _launch(func, *args, **kwargs): # Mimic gevent's default raise_error=False behaviour # by not propagating an exception to the joiner. try: - func(*args, **kwargs) + return func(*args, **kwargs) except TaskExit: pass except: + if raise_error: + raise # Log uncaught exception. # Note: this is an intentional divergence from gevent # behaviour; gevent silently ignores such exceptions. @@ -62,14 +66,18 @@ if HUB_TYPE == 'eventlet': return eventlet.spawn(_launch, *args, **kwargs) def spawn_after(seconds, *args, **kwargs): + raise_error = kwargs.pop('raise_error', False) + def _launch(func, *args, **kwargs): # Mimic gevent's default raise_error=False behaviour # by not propagating an exception to the joiner. try: - func(*args, **kwargs) + return func(*args, **kwargs) except TaskExit: pass except: + if raise_error: + raise # Log uncaught exception. # Note: this is an intentional divergence from gevent # behaviour; gevent silently ignores such exceptions. |