Skip to content

Is it safe to instantiate a resource more then once? #2158

Answered by vytas7
liborjelinek asked this question in Q&A
Discussion options

You must be logged in to vote

Hi again @mattwarrick!
Yes, it is absolutely up to you, the developer, whether it is safe or not.

AFAIK, Falcon doesn't make any assumptions about resource instances apart from (when using the default router) just looking for callable attributes that look like responders (e.g., on_get, on_post, etc). I suppose you might have some (probably negligible) memory savings reusing the same instance, but the framework doesn't mandate it.

Although it is probably a bit strange to instantiate Calculator() again in the above example, but in the case a resource's initializer takes parameters, it might be even desirable to create different resources instances from the same class, for instance:

class Re…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by liborjelinek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants