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 )
@@ -419,8 +424,18 @@ def do_work(st, next_st):
419424 state = copy .copy (next_state )
420425 next_state = copy .copy (next (states ))
421426 do_work (state , next_state )
427+ # for simple scores (e.g. correlations widget) and many feature
428+ # combinations, the 'partial_result_ready' signal (emitted by
429+ # invoking 'task.set_partial_result') was emitted too frequently
430+ # for a longer period of time and therefore causing the widget
431+ # being unresponsive
432+ if can_set_partial_result :
433+ task .set_partial_result (res )
434+ can_set_partial_result = False
435+ Timer (0.01 , reset_flag ).start ()
422436 except StopIteration :
423437 do_work (state , None )
438+ task .set_partial_result (res )
424439 return res
425440
426441
0 commit comments