Multiple Sanic workers with Motor

502 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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