5 ms·
It's not necessary in python (or many other server frameworks), because python doesn't typically follow a model of process-per-request. You can just stick it in
by bpicolo 7y ago
It's not necessary in python (or many other server frameworks), because python doesn't typically follow a model of process-per-request. You can just stick it in memory available to all of your threads.
- tyingq 7y agoI imagine there are python users doing multi-process, aren't there? (since the GIL is limiting for some use cases).
- bpicolo 7y agoYeah - if necessary you can use something like uWSGIs caching interface (https://uwsgi-docs.readthedocs.io/en/latest/Caching.html https://uwsgi-docs.readthedocs.io/en/latest/Caching.html). For most of these sorts of things you'll typically be fine caching the object in question once per process though, because the processes are still persistent. If you truly need shared memory between processes (rather than just an in-memory version of an object used for a lot of requests) there's other options, and it's infrequent that you need something that's shared between request processes but is not shared between other web servers.
- hangonhn 7y agoThey do have the multiprocessing library and you can use that to do some primitive sort of caching between processes but it's not ideal. The pattern I've used before is to use something like Redis to do the caching and then used multiprocessing to create a coordinator process to coordinate between all the worker processes. Multiprocessing is limited in what sort of things you can pass between processes but you have just enough primitives to do some coarse grain coordination.