merry icon indicating copy to clipboard operation
merry copied to clipboard

Async handler support

Open momocow opened this issue 6 years ago • 3 comments

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.

momocow avatar Nov 24 '19 14:11 momocow

Correct, I have no intended to support asyncio back when I wrote this library, but it is a valid request.

miguelgrinberg avatar Nov 24 '19 16:11 miguelgrinberg

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 avatar Nov 25 '19 06:11 momocow

@momocow Yes, always open to improvements and new ideas. :)

miguelgrinberg avatar Nov 25 '19 09:11 miguelgrinberg