How to initialize Sanic worker process

with Sanic we can launcher a group of workers:'', port=port, workers=workers)

My question is, how to initialize these workers respectively? I’m using sanic as a micro-service framework, to communicate with other process, and in sanic process, it need to load different extensions to generate data. Questions is, how to let scanic workers load configuration respectively?

for example, if I have a crawler extension, which need to login into web server before it can crawl web pages, how do I pass account/password to extension in different sanic worker process?

Usually I should use ‘before_server_start’ listener to do the initialization, but seems like it will do the initialization for all workers.

It sounds like you need to create different sanic apps based on different configurations rather than multiple workers.

workers are intended to banlance the work. Not to do different things.

Also, function: def serve_multiple(server_settings, workers) in shows that all workers share same settings.

1 Like