milibopp / obsub

Small python module that implements the observer pattern via a decorator.
Other
12 stars 3 forks source link

Event Handler need to propagates exception raised in the called object #51

Closed nicknolt closed 7 years ago

nicknolt commented 7 years ago

This thread on a forum is explicite about the 'problem' and how need to be the behaviour of the event handler (in my case exceptions are thrown but never catch! And the program continue ... ) : https://stackoverflow.com/questions/1157512/why-do-exceptions-propogate-out-of-an-event-handler

Otherwise, thanks for your lib :)

nicknolt commented 7 years ago

I have wrote a little unit test but the behaviour seems to be correct ... perhaps this is my code (with django.db and GTK), i'm going to close my issues

milibopp commented 7 years ago

@nicknolt interesting to see, that somebody is still using this. :)

Nonetheless, a word of caution: this library is pretty much unmaintained, as there has not been any commit in the last 4 years. Also, see #50 for why the entire architechtural approach to event handling may not be ideal in all situations. That's not to say, that you can't successfully apply it to a given problem. Just be aware of the alternatives that are easier to compose and to test.

nicknolt commented 7 years ago

Your class is simple and efficient, finally this is the handler of GTK (using connect({signal_name}, callback)) wich is problematic, when there is an exception, nobody can catch the exception except with a callback function for unhandled exception (sys.excepthook = uncaught_exception_funtion).

Unit test don't stop and the only way i have found to interrupt is with a sys.exit

I have "wrapped" GTK event to throw a @event event, that the reason why i had a doubt about your lib.

I have see that your code is unmaintained but the pattern Observer is the pattern Observer, and the code seems to be clean.

For the moment, your lib is perfect for my use case, but i'm going to read your post #50 and thinking about.

milibopp commented 7 years ago

Sure thing, I think it is absolutely usable and there is not much need to change it, as it is a fairly simple module. I'm happy that it serves your needs :)