Python sqlite3 and concurrency

前端 未结 14 927
南笙
南笙 2020-11-30 18:00

I have a Python program that uses the \"threading\" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my

14条回答
  •  伪装坚强ぢ
    2020-11-30 18:31

    The following found on mail.python.org.pipermail.1239789

    I have found the solution. I don't know why python documentation has not a single word about this option. So we have to add a new keyword argument to connection function and we will be able to create cursors out of it in different thread. So use:

    sqlite.connect(":memory:", check_same_thread = False)
    

    works out perfectly for me. Of course from now on I need to take care of safe multithreading access to the db. Anyway thx all for trying to help.

提交回复
热议问题