How to use database ds with sqlite3?

Hi PyTango experts!

I was trying to use the Tango database with sqlite3 both with python2 and python3.

I try to launch the database ds with the following command:

zreszela@pc255:~> python -m tango.databaseds.database --port=30000 --logging_level=2 2
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/zreszela/workspace/pytango/tango/databaseds/database.py", line 1880, in <module>
    main()
  File "/home/zreszela/workspace/pytango/tango/databaseds/database.py", line 1765, in main
    get_plugin(options.db_access)
  File "/home/zreszela/workspace/pytango/tango/databaseds/database.py", line 141, in get_plugin
    return __import__(fullname, None, None, fullname)
ImportError: No module named None.sqlite3

For python2 I must patch this to overcome this error:

diff --git a/tango/databaseds/database.py b/tango/databaseds/database.py
index 6d6aa53..df571bb 100644
--- a/tango/databaseds/database.py
+++ b/tango/databaseds/database.py
@@ -137,7 +137,7 @@ def update_timing_stats(dev, time_before, time_after, cmd_name):
 
 
 def get_plugin(name):
-    fullname = '%s.%s' % (db_access.__package__, name)
+    fullname = '%s.%s' % (db_access.__name__, name)
     return __import__(fullname, None, None, fullname)

Then the server hangs on "Initializing database...":

zreszela@pc255:~> python -m tango.databaseds.database --port=30000 --logging_level=2 2
Dummy-1        DEBUG    2019-03-15 12:52:29,963 tango: server loop started
MainThread     DEBUG    2019-03-15 12:52:29,966 sys/database/2: In init_device()
Thread-2       INFO     2019-03-15 12:52:29,967 Sqlite3Database: Initializing database...
submit get_cursor

I added these prints which points to some problem with concurrent.future.ThreadPoolExecutor. When I don't submit the get_cursor method to the executor and execute it directly it works. But then the next submits to the executor hangs...

diff --git a/tango/databaseds/db_access/sqlite3.py b/tango/databaseds/db_access/sqlite3.py
index 4b809b0..5be9b3e 100644
--- a/tango/databaseds/db_access/sqlite3.py
+++ b/tango/databaseds/db_access/sqlite3.py
@@ -60,7 +60,9 @@ def use_cursor(f):
         has_cursor = 'cursor' in kwargs
         cursor = kwargs.pop('cursor', None)
         if not has_cursor:
+            print("submit get_cursor")
             cursor = Executor.submit(self.get_cursor).result()
+            print("after get_cursor")
         self.cursor = cursor
         try:
             ret = Executor.submit(f, *args, **kwargs).result()

Certainly I must be doing something wrong so any kind of tip/guidance would be appreciated. Thanks! I take a profit of this post to ask if someone had tried this on Windows? Finally I would like to use it on windows to avoid the necessity to install MySQL and tango :)

Software versions:

  • PyTango from develop branch insalled with pip install -e --user
  • Tango 9.2.5a with some ALBA patches (I don't think that these are relevant here)