Re: lots of ReadConflictErrors

Jim Fulton <[email protected]>
Newsgroups gmane.comp.web.zope.zodb
Message-ID <CAPDm-FgB3HzcoMpPQNrW7B3_QTTjdeafB35sBYs9XPXUCL2XvQ@mail.gmail.com>
On Fri, Oct 7, 2016 at 7:14 PM, Boylan, Ross <[email protected]> wrote:
> Ah, that goes a good way to meeting my concern.  But isn't that a pretty unusual, i.e., likely to be surprising and confusing, way to use a decorator, and, for that matter, the function definition that follows?

Probably, at least for some.  I wish Python had anonymous functions.
Passing functions to higher-order functions is a common pattern, even
with Python.  Using decorators this way is a compromise.   I chose a
verb as the name of the transaction-manager method to mitigate this.
<shrug>

> Function definitions don't usually execute the code of the function.
>
> Realizing now that functions can be defined inline, i.e., nested, one could have the more verbose but, I think, more conventional,
>   def mainFn():
>
>       @transaction.manager
>       def step1():
>             # some code for your first transaction
>      step1()
>
>       @transaction.manager
>       def step2():
>           # and for the second
>      step2()


Well, you could always:

  def mainFn():

      def step1():
            # some code for your first transaction

      transaction.manager.run(step1)

      def step2():
          # and for the second

      transaction.manager.run(step2)

Jim


-- 
Jim Fulton
http://jimfulton.info

-- 
You received this message because you are subscribed to the Google Groups "zodb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.