Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add callid in the warning log when there is an exception #1249

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions examples/failed_futures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Simple Lithops example using the map method.
In this example the map() method will launch one
map function for each entry in 'iterdata'. Finally
it will print the results for each invocation with
fexec.get_result()
"""
import lithops
import time


def my_map_function(id, x):
print(f"I'm activation number {id}")
time.sleep(2)
if id in [2, 4]:
raise MemoryError()
return x


if __name__ == "__main__":
iterdata = ["a", "b", "c", "d", "e"]

fexec = lithops.FunctionExecutor(log_level='DEBUG')
futures = fexec.map(my_map_function, iterdata)
return_vals = fexec.get_result(fs=futures, throw_except=False)

failed_callids = [int(f.call_id) for f in futures if f.error]

if failed_callids:
new_iterdata = [iterdata[i] for i in failed_callids]
futures = fexec.map(my_map_function, new_iterdata)
new_return_vals = fexec.get_result(fs=futures, throw_except=False)

for i, failed_callid in enumerate(failed_callids):
return_vals[failed_callid] = new_return_vals[i]

print(return_vals)
11 changes: 6 additions & 5 deletions lithops/future.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ def status(self, throw_except=True, internal_storage=None, check_only=False):
self.stats['worker_exec_time'] = round(self.stats['worker_end_tstamp'] - self.stats['worker_start_tstamp'], 8)
total_time = format(round(self.stats['worker_exec_time'], 2), '.2f')

logger.debug(f'ExecutorID {self.executor_id} | JobID {self.job_id} - Got status from call {self.call_id} '
f'- Activation ID: {self.activation_id} - Time: {str(total_time)} seconds')
logger.debug(
f'ExecutorID {self.executor_id} | JobID {self.job_id} - Got status from call {self.call_id} '
f'- Activation ID: {self.activation_id} - Time: {str(total_time)} seconds'
)

if self._call_status['exception']:
self._set_state(ResponseFuture.State.Error)
Expand All @@ -251,8 +253,8 @@ def status(self, throw_except=True, internal_storage=None, check_only=False):
self._exception['exc_traceback'])

logger.warning(
'ExecutorID {} | JobID {} - There was an exception - Activation ID: {} - {}'
.format(self.executor_id, self.job_id, self.activation_id, fn_exctype.__name__)
'ExecutorID {} | JobID {} - CallID: {} - There was an exception - Activation ID: {} - {}'
.format(self.executor_id, self.job_id, self.call_id, self.activation_id, fn_exctype.__name__)
)

def exception_hook(exctype, exc, trcbck):
Expand All @@ -269,7 +271,6 @@ def exception_hook(exctype, exc, trcbck):
sys.excepthook = exception_hook
reraise(*self._exception)
else:
logger.warning(f'Exception: {self._exception[0].__name__} - {self._exception[1]}')
return None

if 'new_futures' in self._call_status and not self._new_futures:
Expand Down
Loading