Skip to content
This repository was archived by the owner on Mar 31, 2019. It is now read-only.

Commit ae1998a

Browse files
committed
only run onupdate if not already running it
1 parent 6d27817 commit ae1998a

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

run/femtocode/run/standalone.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(self, query, ondone, onupdate):
5656
self.computeTime = 0.0
5757
self.data = None
5858
self._lock = threading.Lock()
59+
self._onupdateRunning = threading.Lock()
5960

6061
if ondone is not None:
6162
self._ondone = FutureQueryResult.OnDone(ondone)
@@ -77,12 +78,13 @@ def _update(self, loaded, computed, done, wallTime, computeTime, data):
7778
self.computeTime = computeTime
7879
self.data = data
7980

80-
if self._onupdate is not None:
81-
self._onupdate(data) # not self.data because not in lock
81+
if self._onupdate is not None and not self._onupdateRunning.locked(): # if rapid-fire, skip calls
82+
with self._onupdateRunning:
83+
self._onupdate(data) # not self.data because not in _lock
8284

8385
if done:
8486
if self._ondone is not None:
85-
self._ondone.incoming.put(data) # not self.data because not in lock
87+
self._ondone.incoming.put(data) # not self.data because not in _lock
8688
self._doneevent.set()
8789

8890
def await(self, timeout=None):

0 commit comments

Comments
 (0)