question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQLite objects created in a thread can only be used in that same thread.

See original GitHub issue

Hi @lemon24

Thanks for making this library.

I am attempting to utilise it for a Telegram bot I am working on. However, I run into the following error:

SQLite objects created in a thread can only be used in that same thread.

Here is my code 😃

Doing some quick Google searching I might need to do something similar to what is recommended in this stack overflow post.

However, I cannot see a way I can provide this to the library currently.

Hope you can help. Thanks and a merry Christmas to you! 🎄

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
dbrennandcommented, Jul 9, 2022

Hi @lemon24

This looks awesome! Hopefully I’ll have some time soon to test this out for my bot. Also thanks for the suggestion issue as well 🙂👍🏻

1reaction
lemon24commented, Jul 9, 2022

Hi @dbrennand, starting with reader 2.15, it is now possible to use a reader object from multiple threads; docs.

It should now be possible to have a global Reader object in bot.py. So, instead of this:

async def add_feeds(update, context):
    with contextlib.closing(r.make_reader(READER_DB_PATH)) as reader:
        ... # do stuff with reader

… you can now do this, which should be a bit more ergonomic:

async def add_feeds(update, context):
    with reader:
        ... # do stuff with reader

reader = r.make_reader(READER_DB_PATH)

Some notes:

  • You still have to use the Reader as a context manager. It is not possible to just use it from another thread because I still haven’t figured out a way of reliably running cleanup code on thread exit; the context manager ensures reliable cleanup.
  • You can only do with reader: ... once per thread; this might improve in the future.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Objects created in a thread can only be used in that same thread
By default, check_same_thread is True and only the creating thread may use the connection. If set False, the returned connection may be shared ......
Read more >
Error SQLite objects created in a thread can only be used in ...
My script used to migrate data from SQLite to Postgres in Python. ... SQLite objects created in a thread can only be used...
Read more >
SQLite objects created in a thread can only be used in that ...
PYTHON : ProgrammingError: SQLite objects created in a thread can only be used in that same thread [ Gift : Animated Search Engine ......
Read more >
ProgrammingError: SQLite objects created in a thread can ...
ProgrammingError : SQLite objects created in a thread can only be used in that same thread. The object was created in thread id...
Read more >
SQLite objects created in a thread can only be used in that ...
Error in Debug mode - sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found