isapego commented on a change in pull request #40:
URL: 
https://github.com/apache/ignite-python-thin-client/pull/40#discussion_r648187800



##########
File path: pyignite/aio_client.py
##########
@@ -487,3 +489,21 @@ def get_cluster(self) -> 'AioCluster':
         :return: :py:class:`~pyignite.aio_cluster.AioCluster` instance.
         """
         return AioCluster(self)
+
+    def tx_start(self, concurrency: TransactionConcurrency = 
TransactionConcurrency.PESSIMISTIC,
+                 isolation: TransactionIsolation = 
TransactionIsolation.REPEATABLE_READ,
+                 timeout: Union[int, float] = 0, label: Optional[str] = None) 
-> 'AioTransaction':
+        """
+        Start async thin client transaction.
+
+        :param concurrency: (optional) transaction concurrency, see
+                
:py:class:`~pyignite.datatypes.transactions.TransactionConcurrency`
+        :param isolation: (optional) transaction isolation level, see
+                
:py:class:`~pyignite.datatypes.transactions.TransactionIsolation`
+        :param timeout: (optional) transaction timeout in seconds if float, in 
millis if int
+        :param label: (optional) transaction label.
+        :return: :py:class:`~pyignite.transaction.AioTransaction` instance.
+        """
+        if sys.version_info < (3, 7):
+            raise NotSupportedError(f"Transactions are not supported in async 
client on current python {sys.version}")

Review comment:
       Why python 3.7 is not supported? Does it has to do something with 
`contextvars`?

##########
File path: pyignite/transaction.py
##########
@@ -0,0 +1,130 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import math
+from typing import Union
+
+from pyignite.api.tx_api import tx_end, tx_start, tx_end_async, tx_start_async
+from pyignite.datatypes import TransactionIsolation, TransactionConcurrency
+from pyignite.exceptions import CacheError
+from pyignite.utils import status_to_exception
+
+
+def _convert_to_millis(timeout: Union[int, float]) -> int:
+    if isinstance(timeout, float):
+        return math.floor(timeout * 1000)
+    return timeout
+
+
+class Transaction:
+    """
+    Thin client transaction.
+    """
+    def __init__(self, client, concurrency=TransactionConcurrency.PESSIMISTIC,
+                 isolation=TransactionIsolation.REPEATABLE_READ, timeout=0, 
label=None):
+        self.client, self.concurrency = client, concurrency
+        self.isolation, self.timeout = isolation, _convert_to_millis(timeout)
+        self.label, self.closed = label, False
+        self.tx_id = self.__start_tx()

Review comment:
       Is it OK in python when `__init__` throws exception?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to