You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/06/09 10:58:18 UTC

[GitHub] [ignite-python-thin-client] ivandasch commented on a change in pull request #40: IGNITE-12467 Implement transactions, rewrite async connections using protocol and transport

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



##########
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:
       Yep, it's fine https://stackoverflow.com/questions/1507082/python-is-it-bad-form-to-raise-exceptions-within-init
   




-- 
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:
users@infra.apache.org