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

Multi-threaded Environments向けの記法をしても、sqlite3.ProgrammingErrorが発生する #9

Closed
yukota opened this issue Mar 30, 2021 · 2 comments · Fixed by #10

Comments

@yukota
Copy link
Contributor

yukota commented Mar 30, 2021

現象

以下の記述を行い、マルチスレッド環境から呼び出しを行うと
qlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread.
というExceptionが発生する。
https://github.com/polm/posuto#multi-threaded-environments

トレース

ファイル名一部省略しています

  File ".venv/lib/python3.8/site-packages/posuto/posuto.py", line 38, in get
    return get(code, self._db)
  File ".venv/lib/python3.8/site-packages/posuto/posuto.py", line 75, in get
    base = dict(_fetch_code(code))
  File ".venv/lib/python3.8/site-packages/posuto/posuto.py", line 41, in _fetch_code
    db.execute("select data from postal_data where code = ?", (code,))
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 140153315018560 and this is thread id 140153219274496.

@yukota
Copy link
Contributor Author

yukota commented Mar 30, 2021

_fetch_code呼び出し時に引数のdbを与えていないためPosuto()内のdbが使われていないためだと思います。
https://github.com/polm/posuto/blob/master/posuto/posuto.py#L75

@polm
Copy link
Owner

polm commented Mar 31, 2021

ご報告、そして早速のPRありがとうございます。前回報告を受けたときのテストが甘かったんですね…

月末の更新を反映してからリリースします。

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

Successfully merging a pull request may close this issue.

2 participants