Skip to content

There is an error in the example code #5

@loucadufault

Description

@loucadufault

https://roguelynn.com/words/asyncio-exception-handling/

When the code is corrected to handle exceptions that may be raised by save or restart_host functions, the sample output is given as:

$ python part-3/mayhem_5.py
14:58:15,750 INFO: Consumed PubSubMessage(instance_name='cattle-jmtv')
14:58:15,981 INFO: Saved PubSubMessage(instance_name='cattle-jmtv') into database
14:58:15,981 ERROR: Retrying for failure to restart: cattle-jmtv.example.net
14:58:16,873 INFO: Restarted cattle-hukm.example.net
14:58:16,903 INFO: Done. Acked PubSubMessage(instance_name='cattle-jmtv')

However, the handle_message function was only changed to not raise if one of the tasks passed to asyncio.gather itself raises, and the handling logic only logs a message. So once a RestartFailed exception is raised, we do not expect the same coroutine to eventually resume and then log the line INFO: Restarted cattle-hukm.example.net

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions