From 4a60cac9162f8f2aa25a2de4025493d38113ae54 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 10 May 2015 02:39:45 +0300 Subject: [PATCH] runtime: Add TODO for mp_resume() on handling .close(). Exceptions in .close() should be ignored (dumped to sys.stderr, not propagated), but in uPy, they are propagated. Fix would require nlr-wrapping .close() call, which is expensive. Bu on the other hand, .close() is not called often, so maybe that's not too bad (depends, if it's finally called and that causes stack overflow, there's nothing good in that). And yet on another hand, .close() can be implemented to catch exceptions on its side, and that should be the right choice. --- py/runtime.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/py/runtime.c b/py/runtime.c index 68728642bf..a6cf7e0177 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1113,6 +1113,8 @@ mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t th if (mp_obj_is_subclass_fast(mp_obj_get_type(throw_value), &mp_type_GeneratorExit)) { mp_load_method_maybe(self_in, MP_QSTR_close, dest); if (dest[0] != MP_OBJ_NULL) { + // TODO: Exceptions raised in close() are not propagated, + // printed to sys.stderr *ret_val = mp_call_method_n_kw(0, 0, dest); // We assume one can't "yield" from close() return MP_VM_RETURN_NORMAL;