Slow responsiveness of worker threads
Building off the conversation in #19 it seems that worker threads in python are responding really slowly. it may be that the python GIL isn't really released? Workarounds have included using multiprocessing instead of threading.
The extension I have installed is:
Extension code
import gi
gi.require_version('Nautilus', '3.0')
from gi.repository import Nautilus
from gi.repository import GObject
from threading import Thread
from queue import Queue
# Choose your favorite emblem
emblem = "org.remmina.Remmina-rdp-symbolic"
# emblem = "emblem-favorite-symbolic"
class AddEmblem(GObject.GObject, Nautilus.InfoProvider):
def __init__(self):
self._work_queue = Queue()
self._worker = Thread(
target=self._do_work
)
self._worker.start()
def update_file_info(self, file_info):
file_info.add_emblem(emblem)
def update_file_info_full(self, provider, handle, closure, file_info):
self._work_queue.put((
provider,
handle,
closure,
file_info
))
return Nautilus.OperationResult.IN_PROGRESS
def update_emblem(self, provider, handle, closure, file_info):
file_info.add_emblem(emblem)
Nautilus.info_provider_update_complete_invoke(
closure,
provider,
handle,
Nautilus.OperationResult.COMPLETE
)
def _do_work(self):
from time import perf_counter
start_time = perf_counter()
while True:
provider, handle, closure, file_info = self._work_queue.get()
current_time = perf_counter()
elapsed_time = current_time - start_time
print(f"Working {file_info.get_uri()} {elapsed_time:.2f}")
self.update_emblem(provider, handle, closure, file_info)
Results
14:07 $ nautilus
Initializing nautilus-dropbox 2020.03.04
Working file:///home/mark/Downloads 0.41
Working file:///home/mark/Videos 1.02
Working file:///home/mark/Pictures 1.83
Working file:///home/mark/Music 2.23
Working file:///home/mark/Documents 3.03
Working file:///home/mark/google_drive 3.83
Working file:///home/mark/blackbird 4.43
Working file:///home/mark/raven 5.23
Working file:///home/mark/project_1 6.04
Working file:///home/mark/Fiji.app 6.64
Other developers seem to have noticed the same thing: https://github.com/chrisjbillington/git-nautilus-icons/blob/master/git-nautilus-icons.py#L629