bartongroup / slivka

http://bartongroup.github.io/slivka/
Apache License 2.0
7 stars 3 forks source link

Exceptions caused by batch_submit may not be handled properly. #65

Closed warownia1 closed 4 years ago

warownia1 commented 4 years ago

When the batch_run is called it calls batch submit and returns a generator object. Any errors raised while iterating over the generator are not caught by batch_run but are raised in the caller context.

Example:

def getval(x): raise RuntimeError

def gen():
    try:
         return (getval(x) for x in range(3))
     except:
         print('exception handled')

for _ in gen(): pass  # raises RuntimeError

Changing the signature of gen to:

def gen():
    for i in range(3):
         try:
             yield getval(i)
         except:
             print('exception handled')

handles the exceptions

warownia1 commented 4 years ago

batch_submit runs the jobs immediately end returns an iterable of jobs statuses. Even if the iterable may defer status retrieval, the requirement for batch_run implementations is that it returns after the jobs are started.