def begin(self):
     """
     Begins this transaction.
     """
     if hasattr(self._locals,
                'transaction_exists') and self._locals.transaction_exists:
         raise TransactionError("Nested transactions are not allowed.")
     if self.state != _STATE_NOT_STARTED:
         raise TransactionError("Transaction has already been started.")
     self._locals.transaction_exists = True
     self.start_time = time.time()
     self.thread_id = thread_id()
     try:
         request = transaction_create_codec.encode_request(
             timeout=int(self.timeout * 1000),
             durability=self.durability,
             transaction_type=self.transaction_type,
             thread_id=self.thread_id)
         invocation = Invocation(request,
                                 connection=self.connection,
                                 response_handler=lambda m: m)
         invocation_service = self._context.invocation_service
         invocation_service.invoke(invocation)
         response = invocation.future.result()
         self.id = transaction_create_codec.decode_response(response)
         self.state = _STATE_ACTIVE
     except:
         self._locals.transaction_exists = False
         raise
예제 #2
0
 def begin(self):
     """
     Begins this transaction.
     """
     if hasattr(self._locals,
                'transaction_exists') and self._locals.transaction_exists:
         raise TransactionError("Nested transactions are not allowed.")
     if self.state != _STATE_NOT_STARTED:
         raise TransactionError("Transaction has already been started.")
     self._locals.transaction_exists = True
     self.start_time = time.time()
     self.thread_id = thread_id()
     try:
         request = transaction_create_codec.encode_request(
             timeout=int(self.timeout * 1000),
             durability=self.durability,
             transaction_type=self.transaction_type,
             thread_id=self.thread_id)
         response = self.client.invoker.invoke_on_connection(
             request, self.connection).result()
         self.id = transaction_create_codec.decode_response(
             response)["response"]
         self.state = _STATE_ACTIVE
     except:
         self._locals.transaction_exists = False
         raise
 def begin(self):
     if hasattr(self._locals, "transaction_exists") and self._locals.transaction_exists:
         raise TransactionError("Nested transactions are not allowed.")
     if self.state != _STATE_NOT_STARTED:
         raise TransactionError("Transaction has already been started.")
     self._locals.transaction_exists = True
     self.start_time = time.time()
     self.thread_id = thread_id()
     try:
         request = transaction_create_codec.encode_request(
             timeout=self.timeout * 1000,
             durability=self.durability,
             transaction_type=self.transaction_type,
             thread_id=self.thread_id,
         )
         response = self.client.invoker.invoke_on_connection(request, self.connection).result()
         self.id = transaction_create_codec.decode_response(response)["response"]
         self.state = _STATE_ACTIVE
     except:
         self._locals.transaction_exists = False
         raise