diff options
author | Alex Auvolat <alex@adnab.me> | 2020-03-04 22:52:46 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-03-04 22:52:46 +0100 |
commit | 979755a324dfccd2dd9e7e861825c9082bede99b (patch) | |
tree | 3c9bf42c4ae2a8ad0e92d3c529893730052f8b89 | |
parent | 8e67699fe4c3e78aa5b372c2ded434409f580615 (diff) | |
download | easybridge-979755a324dfccd2dd9e7e861825c9082bede99b.tar.gz easybridge-979755a324dfccd2dd9e7e861825c9082bede99b.zip |
Fix JOIN: do syncing in separate thread (otherwise cache_get doesn't work and we get a deadlock)
-rwxr-xr-x | external/messenger.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/external/messenger.py b/external/messenger.py index 1ce6383..684f7a0 100755 --- a/external/messenger.py +++ b/external/messenger.py @@ -85,18 +85,17 @@ class MessengerBridgeClient(fbchat.Client): # ---- SEPARATE THREADS FOR INITIAL SYNC & CLIENT LISTEN ---- -class InitialSyncThread(threading.Thread): - def __init__(self, client, bridge, threads, *args, **kwargs): - super(InitialSyncThread, self).__init__(*args, **kwargs) +class SyncerThread(threading.Thread): + def __init__(self, client, bridge, thread_queue, *args, **kwargs): + super(SyncerThread, self).__init__(*args, **kwargs) self.client = client self.bridge = bridge - self.threads = threads + self.thread_queue = thread_queue def run(self): - sys.stderr.write("(python) fb thread list: {}\n".format(self.threads)) - - for thread in self.threads: + while True: + thread = self.thread_queue.get(block=True) sys.stderr.write("(python) fb thread: {}\n".format(thread)) self.bridge.setup_joined_thread(thread) @@ -242,7 +241,11 @@ class MessengerBridge: if thread.type == ThreadType.USER: 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() elif ty == CLOSE: @@ -332,7 +335,7 @@ class MessengerBridge: self.my_joined_rooms[thread_id] = True 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): sys.stderr.write("(python) setup_joined_thread {}".format(thread)) |