Skip to content

Commit fd2c952

Browse files
committed
asynchronous: use common.execute to run the function
Signed-off-by: Matteo Cafasso <[email protected]>
1 parent 1ad94f2 commit fd2c952

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

pebble/asynchronous/thread.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from functools import wraps
2121
from traceback import format_exc
2222

23-
from pebble.common import launch_thread
23+
from pebble.common import execute, launch_thread, SUCCESS
2424

2525

2626
def thread(*args, **kwargs) -> Callable:
@@ -79,13 +79,12 @@ def _function_handler(
7979
"""Runs the actual function in separate thread and returns its result."""
8080
loop = future.get_loop()
8181

82-
try:
83-
result = function(*args, **kwargs)
84-
except BaseException as error:
85-
error.traceback = format_exc()
86-
loop.call_soon_threadsafe(future.set_exception, error)
82+
result = execute(function, *args, **kwargs)
83+
84+
if result.status == SUCCESS:
85+
loop.call_soon_threadsafe(future.set_result, result.value)
8786
else:
88-
loop.call_soon_threadsafe(future.set_result, result)
87+
loop.call_soon_threadsafe(future.set_exception, result.value)
8988

9089

9190
def _validate_parameters(name: str, daemon: bool):

0 commit comments

Comments
 (0)