elcorto / psweep

Loop like a pro, make parameter studies fun.
https://elcorto.github.io/psweep
BSD 3-Clause "New" or "Revised" License
13 stars 2 forks source link

Guard failing `worker()` calls #16

Closed elcorto closed 8 months ago

elcorto commented 9 months ago

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).

elcorto commented 9 months ago

However, this implies many additional settings, such as

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.