If you are doing loading of data at "first run of the function" then you have introduced a race condition in your app where unless you do appropriate locking, two threads (most wsgi servers serve a request per thread) may both consider themselves the first run and load the data. The only way to do this without locks is to do things at config-time like I suggested before. There are hacks that you can do because it's Python with a GIL in which you can do locking in more lightweight ways in the "first run of the function" case but I do not recommend relying on that behavior.
As far as defining an object as read-only, there is nothing specific to Pyramid here and you'll have to find a satisfactory solution in the rest of Python world. On Mon, Oct 8, 2018 at 11:20 AM Lukasz Szybalski <szybal...@gmail.com> wrote: > > > On Sunday, October 7, 2018 at 12:59:58 AM UTC-5, Michael Merickel wrote: >> >> This sounds like an application-global object. These are typically stored >> on the registry at config-time. For example, in your main you could set >> config.registry.foo = contract. The registry is available as >> request.registry and subsequently anything you add to it. You can see lots >> of examples of this in pyramid addons and things like the dbsession_factory >> in the alchemy cookiecutter. >> > > Thank you. > > I decided to add it at 1st run of the function: > try: > if not request.registry.mycontract: > request.registry.mycontract = Contract() > mycontract=copy.copy(request.registry.mycontract) > ... > #rest of the code: > mycontract.add_user() > mycontract.update_terms() > > *Sidenote:* > Is there a way to force this object to be "read only" or now allow > modification, to prevent somebody else in some other sections of the code > accidently modifies request.registry.mycontract? > > **update run at 0.42755 sec now. > > Thanks > Lucas > > > > > >> On Sat, Oct 6, 2018 at 5:00 PM Lukasz Szybalski <szyb...@gmail.com> >> wrote: >> >>> Hello, >>> I have an enterprise system that is creating a class but it takes a long >>> time to initiate. About 2 sec, 90K _setitem from pickle. Nothing to >>> profile, since OS cashes the file its as fast as it gets. >>> >>> I'm trying to find a way in pyramid where I can: >>> >>> #store below at start, of the process, let it initiate, >>> #then somehow make it read only, >>> #so that a process can use it later and modify its own copy >>> >>> from enterprise import Contract >>> my= Contract() >>> >>> >>> #rest of the program >>> my2 = copy my (or copy on write, similar how qcow format works) >>> my2.find_contract('abc') >>> my2.add_name('Lucas') >>> return (my2.stuff) >>> >>> I don't seem to be finding the right terminology, or technique to do >>> this, and where to place it in pyramid? >>> >>> Thanks >>> Lucas >>> >>> -- >>> http://lucasmanual.com/ <http://lucasmanual.com/blog/> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "pylons-discuss" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to pylons-discus...@googlegroups.com. >>> To post to this group, send email to pylons-...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/pylons-discuss/CAKkTUv3qgT%2BUk0-uvLB1owZEA3W%3D-7XA-wkiyZbteWHPAcO6vg%40mail.gmail.com >>> <https://groups.google.com/d/msgid/pylons-discuss/CAKkTUv3qgT%2BUk0-uvLB1owZEA3W%3D-7XA-wkiyZbteWHPAcO6vg%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to pylons-discuss+unsubscr...@googlegroups.com. > To post to this group, send email to pylons-discuss@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/pylons-discuss/6590645a-7af6-480a-a866-ab1af78e0d42%40googlegroups.com > <https://groups.google.com/d/msgid/pylons-discuss/6590645a-7af6-480a-a866-ab1af78e0d42%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAKdhhwEJbH1qNNZ2-O8D2ie243nAAXj0knXhf8kXskLYfWYqqA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.