From 6d5035f0299cc21bd8c1d38a8b025d9a63a99811 Mon Sep 17 00:00:00 2001 From: YuK_Ota <318899+yukota@users.noreply.github.com> Date: Tue, 30 Mar 2021 22:13:51 +0900 Subject: [PATCH] Fix exception in multithread environment sqlite cursor can't share different thread context. For this reason, Posuto does't share cursor by calling Posto() But, __fetch_code does't use Posto() provide db. fix #9 --- posuto/posuto.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/posuto/posuto.py b/posuto/posuto.py index f1bb5e3..ca5f799 100644 --- a/posuto/posuto.py +++ b/posuto/posuto.py @@ -37,7 +37,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): def get(self, code): return get(code, self._db) -def _fetch_code(code, db=DB): +def _fetch_code(code, db): db.execute("select data from postal_data where code = ?", (code,)) res = db.fetchone() if res: @@ -72,7 +72,7 @@ def get(code, db=DB): are not handled. """ code = re.sub('[- 〒]', '', code) - base = dict(_fetch_code(code)) + base = dict(_fetch_code(code, db)) # if it's a postal code... if 'prefecture_kana' in base: # now make it a named tuple