Fix JOIN: do syncing in separate thread (otherwise cache_get doesn't work and we get a deadlock)
This commit is contained in:
parent
8e67699fe4
commit
979755a324
1 changed files with 12 additions and 9 deletions
21
external/messenger.py
vendored
21
external/messenger.py
vendored
|
@ -85,18 +85,17 @@ class MessengerBridgeClient(fbchat.Client):
|
||||||
|
|
||||||
# ---- SEPARATE THREADS FOR INITIAL SYNC & CLIENT LISTEN ----
|
# ---- SEPARATE THREADS FOR INITIAL SYNC & CLIENT LISTEN ----
|
||||||
|
|
||||||
class InitialSyncThread(threading.Thread):
|
class SyncerThread(threading.Thread):
|
||||||
def __init__(self, client, bridge, threads, *args, **kwargs):
|
def __init__(self, client, bridge, thread_queue, *args, **kwargs):
|
||||||
super(InitialSyncThread, self).__init__(*args, **kwargs)
|
super(SyncerThread, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.client = client
|
self.client = client
|
||||||
self.bridge = bridge
|
self.bridge = bridge
|
||||||
self.threads = threads
|
self.thread_queue = thread_queue
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
sys.stderr.write("(python) fb thread list: {}\n".format(self.threads))
|
while True:
|
||||||
|
thread = self.thread_queue.get(block=True)
|
||||||
for thread in self.threads:
|
|
||||||
sys.stderr.write("(python) fb thread: {}\n".format(thread))
|
sys.stderr.write("(python) fb thread: {}\n".format(thread))
|
||||||
self.bridge.setup_joined_thread(thread)
|
self.bridge.setup_joined_thread(thread)
|
||||||
|
|
||||||
|
@ -242,7 +241,11 @@ class MessengerBridge:
|
||||||
if thread.type == ThreadType.USER:
|
if thread.type == ThreadType.USER:
|
||||||
self.getUserId(thread)
|
self.getUserId(thread)
|
||||||
|
|
||||||
InitialSyncThread(self.client, self, threads).start()
|
self.sync_thread_queue = queue.Queue(100)
|
||||||
|
SyncerThread(self.client, self, self.sync_thread_queue).start()
|
||||||
|
for thread in threads:
|
||||||
|
self.sync_thread_queue.put(thread)
|
||||||
|
|
||||||
ClientListenThread(self.client).start()
|
ClientListenThread(self.client).start()
|
||||||
|
|
||||||
elif ty == CLOSE:
|
elif ty == CLOSE:
|
||||||
|
@ -332,7 +335,7 @@ class MessengerBridge:
|
||||||
self.my_joined_rooms[thread_id] = True
|
self.my_joined_rooms[thread_id] = True
|
||||||
|
|
||||||
thread = self.client.fetchThreadInfo(thread_id)[thread_id]
|
thread = self.client.fetchThreadInfo(thread_id)[thread_id]
|
||||||
self.setup_joined_thread(thread)
|
self.sync_thread_queue.put(thread)
|
||||||
|
|
||||||
def setup_joined_thread(self, thread):
|
def setup_joined_thread(self, thread):
|
||||||
sys.stderr.write("(python) setup_joined_thread {}".format(thread))
|
sys.stderr.write("(python) setup_joined_thread {}".format(thread))
|
||||||
|
|
Loading…
Reference in a new issue