mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2026-08-21 04:18:12 +02:00
fix(buffers): prevent concurrent manual updates
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
import threading
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import shutil
|
import shutil
|
||||||
import wx
|
import wx
|
||||||
@@ -1520,13 +1521,16 @@ class Controller(object):
|
|||||||
output.speak(_(u"No active session for this buffer."), True)
|
output.speak(_(u"No active session for this buffer."), True)
|
||||||
return
|
return
|
||||||
|
|
||||||
output.speak(_(u"Updating buffer..."), True)
|
update_lock = getattr(bf, "_manual_update_lock", None)
|
||||||
session = bf.session
|
if update_lock is None:
|
||||||
|
update_lock = threading.Lock()
|
||||||
|
bf._manual_update_lock = update_lock
|
||||||
|
if not update_lock.acquire(blocking=False):
|
||||||
|
output.speak(_(u"Updating buffer..."), True)
|
||||||
|
return
|
||||||
|
|
||||||
output.speak(_(u"Updating buffer..."), True)
|
output.speak(_(u"Updating buffer..."), True)
|
||||||
session = bf.session
|
session = bf.session
|
||||||
|
|
||||||
import threading
|
|
||||||
is_blueski = (getattr(session, "KIND", None) == "blueski" or getattr(session, "type", None) == "blueski")
|
is_blueski = (getattr(session, "KIND", None) == "blueski" or getattr(session, "type", None) == "blueski")
|
||||||
|
|
||||||
def do_update_sync():
|
def do_update_sync():
|
||||||
@@ -1556,15 +1560,10 @@ class Controller(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception("Error updating buffer %s", bf.name)
|
log.exception("Error updating buffer %s", bf.name)
|
||||||
wx.CallAfter(output.speak, _("An error occurred while updating the buffer."), True)
|
wx.CallAfter(output.speak, _("An error occurred while updating the buffer."), True)
|
||||||
|
finally:
|
||||||
if is_blueski:
|
update_lock.release()
|
||||||
threading.Thread(target=do_update_sync).start()
|
|
||||||
else:
|
call_threaded(do_update_sync)
|
||||||
# Original async logic for others if needed, but likely they are sync too.
|
|
||||||
# Assuming TWBlue architecture is mostly thread-based for legacy sessions.
|
|
||||||
# If we have an async loop running, we could use it for async-capable sessions.
|
|
||||||
# For safety, let's use the thread approach generally if we are not sure about the loop state.
|
|
||||||
threading.Thread(target=do_update_sync).start()
|
|
||||||
|
|
||||||
|
|
||||||
def get_more_items(self, *args, **kwargs):
|
def get_more_items(self, *args, **kwargs):
|
||||||
|
|||||||
Reference in New Issue
Block a user