'Begin a two-phase or XA transaction and return a transaction
handle.
The returned object is an instance of :class:`.TwoPhaseTransaction`,
which in addition to the methods provided by
:class:`.Transaction`, also provides a
:meth:`~.TwoPhaseTransaction.prepare` method.
:param xid: the two phase transaction id.  If not supplied, a
random id will be generated.
See also :meth:`.Connection.begin`,
:meth:`.Connection.begin_twophase`.'

def begin_twophase(self, xid=None):

    if (self.__transaction is not None):
        raise exc.InvalidRequestError('Cannot    start    a    two    phase    transaction    when    a    transaction    is    already    in    progress.')
    if (xid is None):
        xid = self.engine.dialect.create_xid()
    self.__transaction = TwoPhaseTransaction(self, xid)
    return self.__transaction
