Commits

Kirill Simonov committed 2ce6d93

Added addon `tweak.pgsql.timeout`.

The addon executes `SET SESSION STATEMENT_TIMEOUT TO 60000` for
each open connection.

  • Participants
  • Parent commits a39c5e6

Comments (0)

Files changed (6)

         'engine.mysql = htsql_mysql.export:ENGINE_MYSQL',
         'engine.oracle = htsql_oracle.export:ENGINE_ORACLE',
         'engine.mssql = htsql_mssql.export:ENGINE_MSSQL',
+        'tweak.pgsql.timeout'
+            ' = htsql_tweak.pgsql_timeout.export:TWEAK_PGSQL_TIMEOUT',
     ],
 }
 INSTALL_REQUIRES = [

File src/htsql/util.py

         The package name.
     """
     # Import the package itself.
-    package = __import__(name)
+    package = __import__(name, fromlist=['__name__'])
     # It must be the package we asked for.
     assert hasattr(package, '__name__') and package.__name__ == name
     # Make sure it is indeed a package (has `__name__`).

File src/htsql_tweak/__init__.py

+#
+# Copyright (c) 2006-2011, Prometheus Research, LLC
+# Authors: Clark C. Evans <cce@clarkevans.com>,
+#          Kirill Simonov <xi@resolvent.net>
+#
+
+

File src/htsql_tweak/pgsql_timeout/__init__.py

+#
+# Copyright (c) 2006-2011, Prometheus Research, LLC
+# Authors: Clark C. Evans <cce@clarkevans.com>,
+#          Kirill Simonov <xi@resolvent.net>
+#
+
+

File src/htsql_tweak/pgsql_timeout/connect.py

+#
+# Copyright (c) 2006-2011, Prometheus Research, LLC
+# Authors: Clark C. Evans <cce@clarkevans.com>,
+#          Kirill Simonov <xi@resolvent.net>
+#
+
+
+from htsql_pgsql.connect import ConnectPGSQL
+
+
+class TimeoutConnectPGSQL(ConnectPGSQL):
+
+    statement_timeout = 60
+
+    def open_connection(self, with_autocommit=False):
+        connection = super(TimeoutConnectPGSQL, self).open_connection(
+                                    with_autocommit=with_autocommit)
+        cursor = connection.cursor()
+        cursor.execute("""
+            SET SESSION STATEMENT_TIMEOUT TO %s
+        """ % (self.statement_timeout*1000))
+        return connection
+
+

File src/htsql_tweak/pgsql_timeout/export.py

+#
+# Copyright (c) 2006-2011, Prometheus Research, LLC
+# Authors: Clark C. Evans <cce@clarkevans.com>,
+#          Kirill Simonov <xi@resolvent.net>
+#
+
+
+from htsql.util import autoimport
+from htsql.addon import Addon
+
+
+autoimport('htsql_tweak.pgsql_timeout')
+
+
+class TWEAK_PGSQL_TIMEOUT(Addon):
+    pass
+
+