Search code examples
sanic

Multiple Sanic workers with Motor


I want to use Motor with Sanic but I came across the following text in the documentation:

Threading and forking

Multithreading and forking are not supported; Motor is intended to be used in a single-threaded Tornado application. See Tornado’s documentation on running Tornado in production to take advantage of multiple cores.

Does this mean Motor cannot be used with multiple Sanic workers? Has anybody attempted that?


Solution

  • Sanic is not multi-threaded. And, forking is only used to setup the workers. If you instantiate motor using one of the server life cycle listeners, you will have no problem.

    https://sanicframework.org/en/guide/basics/listeners.html