mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Remove threading.Lock usages
This commit is contained in:
parent
ccb58f503c
commit
81573bce76
@ -19,7 +19,6 @@
|
|||||||
import inspect
|
import inspect
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
from threading import Lock
|
|
||||||
from typing import List, Tuple, Any
|
from typing import List, Tuple, Any
|
||||||
|
|
||||||
from pyrogram import raw
|
from pyrogram import raw
|
||||||
@ -98,10 +97,9 @@ class SQLiteStorage(Storage):
|
|||||||
super().__init__(name)
|
super().__init__(name)
|
||||||
|
|
||||||
self.conn = None # type: sqlite3.Connection
|
self.conn = None # type: sqlite3.Connection
|
||||||
self.lock = Lock()
|
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
with self.lock, self.conn:
|
with self.conn:
|
||||||
self.conn.executescript(SCHEMA)
|
self.conn.executescript(SCHEMA)
|
||||||
|
|
||||||
self.conn.execute(
|
self.conn.execute(
|
||||||
@ -119,19 +117,15 @@ class SQLiteStorage(Storage):
|
|||||||
|
|
||||||
async def save(self):
|
async def save(self):
|
||||||
await self.date(int(time.time()))
|
await self.date(int(time.time()))
|
||||||
|
|
||||||
with self.lock:
|
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
async def close(self):
|
async def close(self):
|
||||||
with self.lock:
|
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
|
||||||
async def delete(self):
|
async def delete(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
async def update_peers(self, peers: List[Tuple[int, int, str, str, str]]):
|
async def update_peers(self, peers: List[Tuple[int, int, str, str, str]]):
|
||||||
with self.lock:
|
|
||||||
self.conn.executemany(
|
self.conn.executemany(
|
||||||
"REPLACE INTO peers (id, access_hash, type, username, phone_number)"
|
"REPLACE INTO peers (id, access_hash, type, username, phone_number)"
|
||||||
"VALUES (?, ?, ?, ?, ?)",
|
"VALUES (?, ?, ?, ?, ?)",
|
||||||
@ -185,7 +179,7 @@ class SQLiteStorage(Storage):
|
|||||||
def _set(self, value: Any):
|
def _set(self, value: Any):
|
||||||
attr = inspect.stack()[2].function
|
attr = inspect.stack()[2].function
|
||||||
|
|
||||||
with self.lock, self.conn:
|
with self.conn:
|
||||||
self.conn.execute(
|
self.conn.execute(
|
||||||
f"UPDATE sessions SET {attr} = ?",
|
f"UPDATE sessions SET {attr} = ?",
|
||||||
(value,)
|
(value,)
|
||||||
@ -221,7 +215,7 @@ class SQLiteStorage(Storage):
|
|||||||
"SELECT number FROM version"
|
"SELECT number FROM version"
|
||||||
).fetchone()[0]
|
).fetchone()[0]
|
||||||
else:
|
else:
|
||||||
with self.lock, self.conn:
|
with self.conn:
|
||||||
self.conn.execute(
|
self.conn.execute(
|
||||||
"UPDATE version SET number = ?",
|
"UPDATE version SET number = ?",
|
||||||
(value,)
|
(value,)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user