Signals and details

I was looking at the Signals (Signals | Sanic Framework) because I wanted to know which signal was thrown.

One thing that would be nice to have is a visual flow of how/when the signals are sent. This would be helpful to know what to do.

Also, having a description of what the signal does and when it is triggered would be helpful too.

One reason I’m asking that is regarding the two following signals:

  • http.lifecycle.response
  • http.lifecycle.exception

I’m not sure, based on the doc, if the http.lifecycle.response will be called when there is an exception, or, in case I want to handle closing the DB for instance, if I need to do that in both signals.

Of course, running a quick script to check gave me the response:

[2022-09-02 11:18:31 +0200] [1542047] [DEBUG] Dispatching signal: http.lifecycle.exception
[2022-09-02 11:18:31 +0200] [1542047] [ERROR] Exception occurred while handling uri:

Exception: Testing exception
[2022-09-02 11:18:31 +0200] [1542047] [DEBUG] Dispatching signal: http.lifecycle.response

Both are run.

But having this indicated in the doc would be nice :slight_smile:

1 Like

Response signal will be triggered whenever any response is sent (whether captured by an exception or not).

Thank you for the clarification.

Is there a signal that is always sent at the end of a request, regardless of what happened (successful, exception, massive failure, etc)?

I want to be sure to properly close all the active connections (Database, Redis, etc).

Yes, the response signal

1 Like