Move objects_lock into the Inventory object
This commit is contained in:
parent
195ce33c83
commit
e4d6ebfc3a
|
@ -63,4 +63,3 @@ outgoing_connections = 8
|
|||
connection_limit = 250
|
||||
|
||||
objects = {}
|
||||
objects_lock = threading.Lock()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import os
|
||||
import sqlite3
|
||||
import threading
|
||||
import time
|
||||
|
||||
from . import shared, structure
|
||||
|
@ -12,6 +13,7 @@ sqlite3.threadsafety = 3
|
|||
class Inventory():
|
||||
"""sqlite inventory"""
|
||||
def __init__(self):
|
||||
self._lock = threading.Lock()
|
||||
self._db = sqlite3.connect(
|
||||
os.path.join(shared.data_directory, 'objects.dat'),
|
||||
check_same_thread=False
|
||||
|
@ -51,7 +53,7 @@ class Inventory():
|
|||
tag=tag, vector=vector)
|
||||
|
||||
def cleanup(self):
|
||||
with shared.objects_lock:
|
||||
with self._lock:
|
||||
self._db.execute(
|
||||
'DELETE FROM objects WHERE expires < ?',
|
||||
(int(time.time()) - 3 * 3600,)
|
||||
|
@ -121,13 +123,13 @@ class Inventory():
|
|||
return item
|
||||
|
||||
def __delitem__(self, vector):
|
||||
with shared.objects_lock: # KeyError
|
||||
with self._lock: # KeyError
|
||||
self._db.execute('DELETE FROM objects WHERE vector = ?', (vector,))
|
||||
self._db.commit()
|
||||
self.rowid = len(self)
|
||||
|
||||
def __setitem__(self, vector, obj):
|
||||
with shared.objects_lock:
|
||||
with self._lock:
|
||||
try:
|
||||
cur = self._db.execute(
|
||||
'INSERT INTO objects VALUES (?,?,?,?,?,?,?,?)', (
|
||||
|
|
Loading…
Reference in New Issue
Block a user