Ok, it looks like the synchronizer instance needs to remain in the calling
scope for the synchronizer to work. This code (Laurence) works:

synch = MySynch()
transaction.manager.registerSynch(synch)

while this code (what we were doing earlier) doesn't:

transaction.manager.registerSynch(MySynch())

Is this a bug or is it supposed to work this way?

Now, regarding the newTransaction() interface method -- this actually looks
very handy and may be just what I need for a mongodb data manager that I'm
writing. But it looks like it's only called when there is an explicit call
to transaction.begin(), which apparently isn't necessary to use the
transaction machinery as it happens implicitly by just using
transaction.get() and then commit()ing. These implicitly begun transactions
don't appear trigger the newTransaction() method in the synchronizer. Is
there any way to make it trigger without an explicit begin()? (this should
probably be the default behavior?)

btw I'm not able to find any of these interface methods by using help() or
dir() on the interfaces in transaction.interfaces. All of the interfaces
appear to show exactly the same set of properties and methods... though I
do see them if I look directly in the transaction/interfaces.py source. is
there another way to introspect these?

Thanks, -Sid


On Sun, Mar 3, 2013 at 10:28 AM, Laurence Rowe <laurencer...@gmail.com>wrote:

> On 3 March 2013 08:37, Carlos de la Guardia
> <carlos.delaguar...@gmail.com> wrote:
> > Laurence, did you get it to work like that? I tried before using
> > classmethod and wasn't able to make it work.
>
> Ah, you need to implement all methods on ISynchronizer:
>
> >>> class MySynch(object):
> ...     def newTransaction(self, transaction):
> ...         pass
> ...
> KeyboardInterrupt
> >>> class MySynch(object):
> ...     def newTransaction(self, transaction):
> ...         print "New transaction"
> ...     def beforeCompletion(self, transaction):
> ...         print "Commit started"
> ...     def afterCompletion(self, transaction):
> ...         print "Commit finished"
> ...
> >>> import transaction
> >>> synch = MySynch()
> >>> transaction.manager.registerSynch(synch)
> >>> tx = transaction.begin()
> New transaction
> >>> tx.commit()
> Commit started
> Commit finished
>
> If you want a singleton synchronizer then you can use classmethods
> everywhere, but you'll still need to implement them all.
>
> Laurence
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pylons-devel+unsubscr...@googlegroups.com.
> To post to this group, send email to pylons-devel@googlegroups.com.
> Visit this group at http://groups.google.com/group/pylons-devel?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-devel+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/pylons-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to