Skip to content

Commit 81573bc

Browse files
committed
Remove threading.Lock usages
1 parent ccb58f5 commit 81573bc

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

pyrogram/storage/sqlite_storage.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import inspect
2020
import sqlite3
2121
import time
22-
from threading import Lock
2322
from typing import List, Tuple, Any
2423

2524
from pyrogram import raw
@@ -98,10 +97,9 @@ def __init__(self, name: str):
9897
super().__init__(name)
9998

10099
self.conn = None # type: sqlite3.Connection
101-
self.lock = Lock()
102100

103101
def create(self):
104-
with self.lock, self.conn:
102+
with self.conn:
105103
self.conn.executescript(SCHEMA)
106104

107105
self.conn.execute(
@@ -119,24 +117,20 @@ async def open(self):
119117

120118
async def save(self):
121119
await self.date(int(time.time()))
122-
123-
with self.lock:
124-
self.conn.commit()
120+
self.conn.commit()
125121

126122
async def close(self):
127-
with self.lock:
128-
self.conn.close()
123+
self.conn.close()
129124

130125
async def delete(self):
131126
raise NotImplementedError
132127

133128
async def update_peers(self, peers: List[Tuple[int, int, str, str, str]]):
134-
with self.lock:
135-
self.conn.executemany(
136-
"REPLACE INTO peers (id, access_hash, type, username, phone_number)"
137-
"VALUES (?, ?, ?, ?, ?)",
138-
peers
139-
)
129+
self.conn.executemany(
130+
"REPLACE INTO peers (id, access_hash, type, username, phone_number)"
131+
"VALUES (?, ?, ?, ?, ?)",
132+
peers
133+
)
140134

141135
async def get_peer_by_id(self, peer_id: int):
142136
r = self.conn.execute(
@@ -185,7 +179,7 @@ def _get(self):
185179
def _set(self, value: Any):
186180
attr = inspect.stack()[2].function
187181

188-
with self.lock, self.conn:
182+
with self.conn:
189183
self.conn.execute(
190184
f"UPDATE sessions SET {attr} = ?",
191185
(value,)
@@ -221,7 +215,7 @@ def version(self, value: int = object):
221215
"SELECT number FROM version"
222216
).fetchone()[0]
223217
else:
224-
with self.lock, self.conn:
218+
with self.conn:
225219
self.conn.execute(
226220
"UPDATE version SET number = ?",
227221
(value,)

0 commit comments

Comments
 (0)