Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vdsql-] ensure each thread in vdsql tracks its single connection #2704

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

anjakefala
Copy link
Collaborator

@anjakefala anjakefala commented Feb 11, 2025

Uses threading.local to keep track of a thread's connection.

Otherwise, you occassionally get this error when opening an SQLite table with vdsql:

Traceback (most recent call last):
  File "/home/anja/anaconda3/envs/visidata/lib/python3.11/threading.py", line 995, in _bootstrap
    self._bootstrap_inner()
  File "/home/anja/anaconda3/envs/visidata/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/home/anja/anaconda3/envs/visidata/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/home/anja/git/visidata/visidata/threads.py", line 209, in _with_active_cmd
    _toplevelTryFunc(func, *args, **kwargs)
  File "/home/anja/git/visidata/visidata/threads.py", line 227, in _toplevelTryFunc
    t.status = func(*args, **kwargs)
  File "/home/anja/git/visidata/visidata/sheets.py", line 281, in reload
    self.loader()
  File "/home/anja/git/visidata/visidata/sheets.py", line 307, in loader
    for i, r in enumerate(self.iterload()):
  File "/home/anja/git/visidata/visidata/apps/vdsql/_ibis.py", line 357, in iterload
    self.query = self.baseQuery(con)
  File "/home/anja/git/visidata/visidata/apps/vdsql/_ibis.py", line 345, in baseQuery
    tbl = con.table(self.table_name)
  File "/home/anja/anaconda3/envs/visidata/lib/python3.11/site-packages/ibis/backends/sql/__init__.py", line 100, in table
    table_schema = self.get_schema(name, catalog=catalog, database=database)
  File "/home/anja/anaconda3/envs/visidata/lib/python3.11/site-packages/ibis/backends/sqlite/__init__.py", line 298, in get_schema
    with self.begin() as cur:
  File "/home/anja/anaconda3/envs/visidata/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
  File "/home/anja/anaconda3/envs/visidata/lib/python3.11/site-packages/ibis/backends/sqlite/__init__.py", line 147, in begin
    cur = self.con.cursor()
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 139669398107904 and this is thread id 139668276848384.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant