forked from Tapanhaz/Shoonya_OptionChainStreamer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.py
More file actions
39 lines (31 loc) · 1.01 KB
/
Copy pathshared.py
File metadata and controls
39 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import threading
class SharedDict:
def __init__(self):
self.feedJson = {}
self.lock = threading.Lock()
def read(self, key):
with self.lock:
return self.feedJson.get(key, None)
def write(self, key, value):
with self.lock:
if key in self.feedJson:
self.feedJson[key].update(value)
else:
self.feedJson[key] = value
def get(self):
with self.lock:
return self.feedJson
class SharedList:
def __init__(self):
self.tokenlist = []
self.lock = threading.Lock()
def get(self):
with self.lock:
return self.tokenlist
def append(self, itemList):
with self.lock:
self.tokenlist.extend(itemList)
def remove(self, itemList):
with self.lock:
itemsSet = set(itemList)
self.tokenlist = [item for item in self.tokenlist if item not in itemsSet]