77from queue import Queue , Empty
88from types import SimpleNamespace as namespace
99from typing import Optional , Iterable , List , Callable
10+ from threading import Timer
1011
1112from AnyQt .QtCore import Qt , QSize , pyqtSignal as Signal , QSortFilterProxyModel
1213from AnyQt .QtGui import QStandardItemModel , QStandardItem , QColor , QBrush , QPen
@@ -393,6 +394,7 @@ def run_vizrank(compute_score: Callable, iterate_states: Callable,
393394 task .set_status ("Getting scores..." )
394395 res = Result (queue = Queue (), scores = None )
395396 scores = scores .copy ()
397+ can_set_partial_result = True
396398
397399 def do_work (st , next_st ):
398400 try :
@@ -405,7 +407,10 @@ def do_work(st, next_st):
405407 except Exception : # ignore current state in case of any problem
406408 pass
407409 res .scores = scores .copy ()
408- task .set_partial_result (res )
410+
411+ def reset_flag ():
412+ nonlocal can_set_partial_result
413+ can_set_partial_result = True
409414
410415 state = None
411416 next_state = next (states )
@@ -418,8 +423,18 @@ def do_work(st, next_st):
418423 state = copy .copy (next_state )
419424 next_state = copy .copy (next (states ))
420425 do_work (state , next_state )
426+ # for simple scores (e.g. correlations widget) and many feature
427+ # combinations, the 'partial_result_ready' signal (emitted by
428+ # invoking 'task.set_partial_result') was emitted too frequently
429+ # for a longer period of time and therefore causing the widget
430+ # being unresponsive
431+ if can_set_partial_result :
432+ task .set_partial_result (res )
433+ can_set_partial_result = False
434+ Timer (0.01 , reset_flag ).start ()
421435 except StopIteration :
422436 do_work (state , None )
437+ task .set_partial_result (res )
423438 return res
424439
425440
0 commit comments