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

Commit

Permalink
only run onupdate if not already running it
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski committed Apr 19, 2017
1 parent 6d27817 commit ae1998a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions run/femtocode/run/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self, query, ondone, onupdate):
self.computeTime = 0.0
self.data = None
self._lock = threading.Lock()
self._onupdateRunning = threading.Lock()

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

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

if done:
if self._ondone is not None:
self._ondone.incoming.put(data) # not self.data because not in lock
self._ondone.incoming.put(data) # not self.data because not in _lock
self._doneevent.set()

def await(self, timeout=None):
Expand Down

0 comments on commit ae1998a

Please sign in to comment.