Ok - loving Sanic more and more every day !
Latest problem is this :
At top of my py file (runs when the server starts) I load a dict into sql_lines
from a saved pickle. It is a global dict used far and wide across my codeā¦ I notice in the Sanic console that it actually runs (i.e. loads) multiple times , seems to be: number_of_workers + 1
.
I see 2 possible solutions to this ā¦ Need some sample code and some advice about which of the 2 solutions is the better approach for me .
Assume I have 5 workers.
Option 1: if one of the workers updates the dict sql_lines
, and saves it into the pickle, that worker should somehow signal to the other workers to refresh (i.e. reload) their copy. How ?
OR
Option 2: Somehow tell Sanic - "only load sql_lines
once, not (number_of_workers + 1)
times "
Obviously if it is only loaded once as per Option 2, (which is my preferred approach), I need to be SURE that Sanic will manage it and will make sure sql_lines
can still be accessed across all workers and all functions .
Please advise me - and try not to be too harsh about my (growing, but still beginner level) depth of understanding of Sanic.