merry
merry copied to clipboard
Async handler support
Hi, I just found this package useful along with your another package python-socketio, or I'll have to make all my event handlers started with try-except clauses.
However, python-socketio accepts async functions as handlers, while I find out that this package seems does not support async error handlers.
In the example, I read about this.
@merry._except(Exception)
def catch_all():
db = getattr(merry.g, 'database', None)
if db is not None and is_database_open(db):
close_database(db)
print('Unexpected error, quitting')
sys.exit(1)
If it is a reasonable use case, the close_database is the most likely to be an async operation. Therefore I suppose that async error handler is a reasonable request.
Thank you.
Correct, I have no intended to support asyncio back when I wrote this library, but it is a valid request.
I have come up with some ideas about the package and the API, for better mimic the try-except clause (also support async handler). Can I send a PR to demo about it?
@momocow Yes, always open to improvements and new ideas. :)