From 81573bce764fa4c2e5bd9ea1b0451154c7fe014e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 23 Dec 2022 20:20:27 +0100 Subject: [PATCH] Remove threading.Lock usages --- pyrogram/storage/sqlite_storage.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/pyrogram/storage/sqlite_storage.py b/pyrogram/storage/sqlite_storage.py index 15e5ddc0..e28b9b74 100644 --- a/pyrogram/storage/sqlite_storage.py +++ b/pyrogram/storage/sqlite_storage.py @@ -19,7 +19,6 @@ import inspect import sqlite3 import time -from threading import Lock from typing import List, Tuple, Any from pyrogram import raw @@ -98,10 +97,9 @@ class SQLiteStorage(Storage): super().__init__(name) self.conn = None # type: sqlite3.Connection - self.lock = Lock() def create(self): - with self.lock, self.conn: + with self.conn: self.conn.executescript(SCHEMA) self.conn.execute( @@ -119,24 +117,20 @@ class SQLiteStorage(Storage): async def save(self): await self.date(int(time.time())) - - with self.lock: - self.conn.commit() + self.conn.commit() async def close(self): - with self.lock: - self.conn.close() + self.conn.close() async def delete(self): raise NotImplementedError async def update_peers(self, peers: List[Tuple[int, int, str, str, str]]): - with self.lock: - self.conn.executemany( - "REPLACE INTO peers (id, access_hash, type, username, phone_number)" - "VALUES (?, ?, ?, ?, ?)", - peers - ) + self.conn.executemany( + "REPLACE INTO peers (id, access_hash, type, username, phone_number)" + "VALUES (?, ?, ?, ?, ?)", + peers + ) async def get_peer_by_id(self, peer_id: int): r = self.conn.execute( @@ -185,7 +179,7 @@ class SQLiteStorage(Storage): def _set(self, value: Any): attr = inspect.stack()[2].function - with self.lock, self.conn: + with self.conn: self.conn.execute( f"UPDATE sessions SET {attr} = ?", (value,) @@ -221,7 +215,7 @@ class SQLiteStorage(Storage): "SELECT number FROM version" ).fetchone()[0] else: - with self.lock, self.conn: + with self.conn: self.conn.execute( "UPDATE version SET number = ?", (value,)