<div dir="ltr"><div>So, we started using storm recently and we are still in a development process, but before going any further, we want to know if we are making things right.</div><div><br></div><div>The application being built is a REST API developed using Falcon Framework.</div>
<div><br></div><div>When the application starts, we import a file (models.meta) which has the following code</div><div><br></div><div>...</div><div>database_dsn = "%s://%s:%s@%s:%s/%s" % (db_driver, db_user, db_pwd, db_host, db_port, db_name)</div>
<div>from zope.component import provideUtility, getUtility</div><div>from storm.zope.interfaces import IZStorm</div><div>from storm.zope.zstorm import global_zstorm</div><div>provideUtility(global_zstorm, IZStorm)</div><div>
zstorm = getUtility(IZStorm)</div><div>zstorm.set_default_uri("store_provider", database_dsn)</div><div><br></div><div>And, in the file that contains the class that handles the calls to a particular entity in the REST API has the following (abbreviated):</div>
<div><br></div><div>from models.meta import zstorm</div><div>class LoginResource:</div><div>    # POST /login</div><div>    def on_post(self, req, resp):</div><div>        store = zstorm.get("store_provider")</div>
<div>        user = store.find...</div><div>...</div><div><br></div><div>So, the code above is the basic idea we are currently starting to use.<br></div><div>I wanted to know if just by doing: store = zstorm.get("store_provider") in each function that handles a particular request, is enough to guarantee that the app will be thread-safe and, for example, that 2 concurrent requests will get their non-blocking stores and use the database without blocking each other? (storm does this internally and transparently for the developer?)</div>
<div><br></div><div><div>I read the following in Storm-Manual:</div><div>"Therefore, the best policy is usually to create a Store object for each thread which needs one. One convenient way to manage this is to implement a "threadsafe" Store manager, which creates a Store for each thread when that thread first requests one, and then keeps the Store cached in a thread-local dictionary. This approach is taken by ZStorm to provide Store objects to each thread."</div>
<div><br></div></div><div>If our idea above is wrong, what would we could do to make our app thread-safe?</div><div><br></div><div>Thanks a lot in advance for any help</div><div>Regards.</div></div>