elcorto/psweep

Guard failing `worker()` calls

elcorto opened this issue · 1 comments

Users can catch exceptions and add a _failed field like so:

import traceback

def func(pset):
    ... here be code ...
    return dict(...)

def safe_func(pset):
    try:
        ret = func(pset)
        ret.update(_failed=False, _exc_txt=None)
    except:
        txt = traceback.format_exc()
        print(f"{pset=} failed, traceback:\n{txt}")
        ret.update(_failed=True, _exc_txt=txt)
    return ret

ps.run(safe_func, params)

Maybe make this a feature, e.g. run(..., guard_worker=True).

However, this implies many additional settings, such as

  • db field names
  • store exception text in db?
  • print exception text?

Given that this can be solved by a small user-written wrapper as shown above, maybe don't codify that just yet, rather provide this as example and/or section in the manual.