Finally resolved UI thread overloads
This commit is contained in:
@@ -12,12 +12,14 @@ from ..widgets.file_preview_widget import FilePreviewWidget
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
|
||||
|
||||
return wrapper
|
||||
|
||||
# NOTE: Threads WILL die with parent's destruction.
|
||||
def daemon_threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
@@ -25,6 +27,7 @@ class FileSearchMixin:
|
||||
def _run_find_file_query(self, widget=None, eve=None):
|
||||
self._handle_find_file_query(query=widget)
|
||||
|
||||
# TODO: Merge this logic with nearly the exact same thing in grep_search_mixin
|
||||
@daemon_threaded
|
||||
def _handle_find_file_query(self, widget=None, eve=None, query=None):
|
||||
# NOTE: Freeze IPC consumption
|
||||
@@ -33,19 +36,15 @@ class FileSearchMixin:
|
||||
|
||||
# NOTE: Kill the former process
|
||||
if self._list_proc:
|
||||
if self._list_proc.poll():
|
||||
self._list_proc.send_signal(signal.SIGKILL)
|
||||
while self._list_proc.poll():
|
||||
pass
|
||||
if self._list_proc.poll() == None:
|
||||
self._list_proc.terminate()
|
||||
while self._list_proc.poll() == None:
|
||||
...
|
||||
|
||||
self._list_proc = None
|
||||
else:
|
||||
self._list_proc = None
|
||||
self._list_proc = None
|
||||
|
||||
# NOTE: Clear children from ui and make sure ui thread redraws
|
||||
GLib.idle_add(self.clear_children, self._file_list)
|
||||
while len(self._file_list.get_children()) > 0:
|
||||
time.sleep(0.2)
|
||||
GLib.idle_add(self.reset_file_list_box)
|
||||
|
||||
# NOTE: If query create new process and do all new loop.
|
||||
self.pause_fifo_update = False
|
||||
@@ -62,9 +61,6 @@ class FileSearchMixin:
|
||||
self._list_proc = subprocess.Popen(command, cwd=self.path, stdin=None, stdout=None, stderr=None)
|
||||
|
||||
def _load_file_ui(self, data):
|
||||
if self.pause_fifo_update:
|
||||
return
|
||||
|
||||
if not data in ("", None):
|
||||
jdata = json.loads( data )
|
||||
target = jdata[0]
|
||||
|
@@ -12,12 +12,14 @@ from ..widgets.grep_preview_widget import GrepPreviewWidget
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
|
||||
|
||||
return wrapper
|
||||
|
||||
# NOTE: Threads WILL die with parent's destruction.
|
||||
def daemon_threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
@@ -25,6 +27,7 @@ class GrepSearchMixin:
|
||||
def _run_grep_query(self, widget=None, eve=None):
|
||||
self._handle_grep_query(query=widget)
|
||||
|
||||
# TODO: Merge this logic with nearly the exact same thing in file_search_mixin
|
||||
@daemon_threaded
|
||||
def _handle_grep_query(self, widget=None, eve=None, query=None):
|
||||
# NOTE: Freeze IPC consumption
|
||||
@@ -33,19 +36,15 @@ class GrepSearchMixin:
|
||||
|
||||
# NOTE: Kill the former process
|
||||
if self._grep_proc:
|
||||
if self._grep_proc.poll():
|
||||
self._grep_proc.send_signal(signal.SIGKILL)
|
||||
while self._grep_proc.poll():
|
||||
pass
|
||||
if self._grep_proc.poll() == None:
|
||||
self._grep_proc.terminate()
|
||||
while self._grep_proc.poll() == None:
|
||||
...
|
||||
|
||||
self._grep_proc = None
|
||||
else:
|
||||
self._grep_proc = None
|
||||
self._grep_proc = None
|
||||
|
||||
# NOTE: Clear children from ui and make sure ui thread redraws
|
||||
GLib.idle_add(self.clear_children, self._grep_list)
|
||||
while len(self._grep_list.get_children()) > 0:
|
||||
time.sleep(0.2)
|
||||
GLib.idle_add(self.reset_grep_box)
|
||||
|
||||
# NOTE: If query create new process and do all new loop.
|
||||
self.pause_fifo_update = False
|
||||
@@ -62,9 +61,6 @@ class GrepSearchMixin:
|
||||
self._grep_proc = subprocess.Popen(command, cwd=self.path, stdin=None, stdout=None, stderr=None)
|
||||
|
||||
def _load_grep_ui(self, data):
|
||||
if self.pause_fifo_update:
|
||||
return
|
||||
|
||||
if not data in ("", None):
|
||||
jdata = json.loads( data )
|
||||
jkeys = jdata.keys()
|
||||
|
Reference in New Issue
Block a user